This discussion is archived
2 Replies Latest reply: Feb 13, 2013 1:26 PM by aksarben RSS

Can anyone explain me concept of Recursion?

885358 Newbie
Currently Being Moderated
Hi All,
Im struggling for understanding the concept of Recursion from past many days . can anyone please explain me how it works with the below example.
public class Permutation {

    /**
     * @param args the command line arguments
     */
     public static String name;
    public static void main(String[] args)throws Exception {
    DataInputStream dis=new DataInputStream(System.in);
    name=dis.readLine();
    
    permutation("", name);
    }

    private static  void permutation(String prefix,String str){
        int n=str.length();
        if(n==0){
            System.out.println(prefix);
        }else{
            for (int i = 0; i < str.length(); i++) {
             permutation(prefix+str.charAt(i),str.substring(0, i)+str.substring(i+1, n) );
            }
   
        }
    }
Thanks and Regards,
Mahesh M

Edited by: Mahesh M on 13 Feb, 2013 7:31 AM

Edited by: EJP on 13/02/2013 20:25: revised your bizarre formatting to use {noformat}
{noformat} tags: please use them.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points