Method calling itself Recursion example





 Here  is  simple  example  of  method  calling itself .   You  can  see  in this  code  method
  mrc()   calling  itself.





public class Recursionmethods {

public  static  int  i=0;
  public static  int   mrc() {
 
      i++;
 
  if ( i<=9) {
             
  System.out.println("mukesh"+i);         
 
    mrc();
     
      }
   
      return i;
 
        }
public static void main(String[] args) {
// TODO Auto-generated method stub
int k =     mrc();
         
System.out.println( k);
}

}


 Program  out   will be  like  this .. 

mukesh1
mukesh2
mukesh3
mukesh4
mukesh5
mukesh6
mukesh7
mukesh8
mukesh9
10

Method calling itself Recursion example  Method  calling  itself  Recursion example Reviewed by Mukesh Jha on 4:10 AM Rating: 5

No comments:

Add your comment

All Right Reserved To Mukesh Jha.. Theme images by Jason Morrow. Powered by Blogger.