In Fibonacci series, next number is the sum of previous two numbers for example 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 etc. The first two numbers of Fibonacci series are 0 and 1.
There are two ways to write the Fibonacci series program in java:
• Fibonacci Series without using recursion
• Fibonacci Series using recursion
Fibonacci Series in Java without using recursion
Let's see the Fibonacci series program in java without using recursion.
public class FibonacciExample{
public static void main(String[] args){
int fn1 = 0, fn2 = 1, rn,i, count = 10; // fn =fibonaccinumber, rn = resultnumber;
System.out.print(fn1+" "+fn2); // printing 0 and 1
for(i=2;i<count; i++){
rn = fn1+fn2;
System.out.print(" "+rn);
fn1=fn2;
fn2=rn;
}
}
}
output:
0 1 1 2 3 5 8 13 21 34
Will you help me in Java programming?
#md_afjal
Yeah.
help full post
ThnQ