- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFibonacci.java
More file actions
Latest commit
39 lines (27 loc) · 663 Bytes
/
Copy pathFibonacci.java
File metadata and controls
39 lines (27 loc) · 663 Bytes
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
packagepractice;
importjava.util.Scanner;
publicclassFibonacci {
publicstaticvoidmain(String[] args) {
System.out.println("Program to generate a fibonacci series!\n---");
Scannerss = newScanner(System.in);
System.out.print("Enter the value of n: ");
intn = ss.nextInt();
if (n>30 || n<0) {
System.out.println("Out of limit");
end();
}
ss.close();
intlb = 0, ub = 1, temp = 0;
for (inti = 0; i < n; i++) {
System.out.print(lb+" ");
temp = ub + lb;
lb = ub;
ub = temp;
}
end();
}
privatestaticvoidend() {
System.out.println("\n---\nThe Program has ended.");
System.exit(0);
}
}