Fibbonacci_No_Generation

package fibbonacci_no_generation;
import java.util.Scanner;
public class Fibbonacci_No_Generation {
public static void main(String[] args) {
int n1=0,n2=1,n3;
Scanner sc=new Scanner(System.in);
System.out.println("enter number of terms to get fibonacci series");
int count=sc.nextInt();
System.out.print("The numbers are "+n1 +","+n2);
for (int i = 2; i <count; i++) {
n3=n1+n2;
System.out.print(","+n3);
n1=n2;
n2=n3;
}
}
}

                                                        OUTPUT


enter number of terms to get fibonacci series
5
The numbers are 0,1,1,2,3

No comments:

Post a Comment