package com.tutorial4u;
import java.util.Scanner;
public class FibonacciSeriesExample {
public static void main(String[] args) {
int first = 0,second=1, temp;
System.out.print("Enter any number : ");
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
System.out.print(first+" "+second+" ");
for(int i =2;i<num;i++){
temp = first+second;
first=second;
second= temp;
System.out.print(temp+" ");
}
}
}
Output:
Enter
any number : 12
0 1 1 2 3 5 8 13 21 34 55
89
No comments:
Post a Comment