Results 1 to 3 of 3

Thread: recursive function

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2003
    Location
    pakistan
    Posts
    2

    recursive function

    i want to know how will it give result using recursive in java
    1 1 2 3 5 8 13 21 34
    fozi

  2. #2

  3. #3
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Code:
      public class Fib{
       public static void main(String[] args){
      
       calculate(0,0,0,0); 
     }
      private static void calculate(int f1, int f2,int temp,int counter){
       
       temp = f2; 
       f2 = f1 + f2; 
       f1 = temp; 
       f1 = f1 + 1;
      
       System.out.println(f1);
      
       counter  = counter + 1;
     
      if(counter == 10) return; 
       calculate(f1,f2,temp,counter); 
      }
     }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width