Fibonacci Series: In this series, next number is the sum of previous two numbers.
Example: 0,1,1,2,3,5,8,13,21....
public class FiboonacciProgram {
public static void main(String[] args) {
int n1=0,n2=1,n=10,n3;
System.out.println(n1+" "+n2);
for(int i=2; i<=n;i++){
n3=n1+n2;
System.out.print(" "+n3);
n1=n2;
n2=n3;
}
}
}
No comments:
Post a Comment