i want to know how will it give result using recursive in java
1 1 2 3 5 8 13 21 34
Printable View
i want to know how will it give result using recursive in java
1 1 2 3 5 8 13 21 34
Looking to calculate a Fibonacci sequence?
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);
}
}