-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fibonacci.java
60 lines (40 loc) · 1.24 KB
/
Fibonacci.java
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import java.util.Scanner;
public class Fibonacci {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Input the number: ");
int n = in.nextInt();
int count = 1;
int no_of_spaces = 1;
int start = 0;
for (int i = 1; i < (n * 2); i++){
for (int spc = n - no_of_spaces; spc > 0; spc--) {
System.out.print(" ");
}
if (i < n){
start = i; //for number
no_of_spaces++; //for spaces
}
else{
start = n * 2 - i; //for number
no_of_spaces--; //for space
}
for (int j = 0; j < count; j++){
System.out.print(start);
if (j < count / 2){
start--;
}
else{
start++;
}
}
if (i < n){
count = count + 2;
}
else {
count = count - 2;
}
System.out.println();
}
}
}