Java Program 06 - Produce Fibonacci Series Upto N Number - Study Viral
//Java Program - 06 - Write a Java Program to produce
//Fibonacci series upto n number of times.
import java.util.Scanner;
class StudyViral_06{
public static void main(String []args){
Scanner sc = new Scanner(System.in);
int n ;
int a = 0;
int b = 1;
System.out.println("Please Enter a Number :: ");
n = sc.nextInt();
System.out.println("Fibonacci Series is :: ");
System.out.print(""+a+"\t"+b);
for(int i = 2;i<=n;i++){
int c = a + b;
System.out.print("\t"+c);
a = b;
b = c;
}
}
}
Output ::
0 comments:
Post a Comment