HOW THIS RECURSION WORKS IN JAVA

 class fact  
 {  
      public static void main(String[]args)  
           {  
                repeat(4);   
           System.out.println("Hello world");  
           }  
      public static void repeat(int a)  
           {  
                System.out.print(a);   
                if(a<=0) return ;   
                else{  
                 repeat(a-1);  
                 repeat(a-1);  
                }   
           }  
 }  
 /*  
 out put:   
 4321001002100100321001002100100Hello world  
 */  

Post a Comment

0 Comments