-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFibonacciSeries.java
More file actions
43 lines (40 loc) · 1.25 KB
/
FibonacciSeries.java
File metadata and controls
43 lines (40 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import java.util.Scanner;
public class FibonacciSeries {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
//input number of which wanna print fib
System.out.println("Enter a number: ");
int num = scan.nextInt();
int a = 0;
int b = 1;
//loop
int i=0;
int fib;
System.out.println("FIBONACCI SERIES OF "+num+" : ");
System.out.println("##############################################");
while(i != num){
if (i == 0){
fib = a;
System.out.print(fib);
// System.out.print(" ");
}
else if(i == 1){
fib = b;
System.out.print(" ");
System.out.print(fib);
}
else{
fib = a+ b;
a = b;
b = fib;
System.out.print(" ");
System.out.print(fib);
}
i++;
}
System.out.println();
System.out.println("##############################################");
System.out.print("Thank You!");
scan.close();
}
}