-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFibonacci.java
More file actions
33 lines (30 loc) · 737 Bytes
/
Fibonacci.java
File metadata and controls
33 lines (30 loc) · 737 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
import java.util.Scanner;
public class Fibonacci {
public static void name(int n) {
int a0 = 0, a1 = 1, a3;
if(n == 0) {
System.out.print("");
return;
}
else if(n == 1) {
System.out.print("0");
return;
}
else if(n == 2) {
System.out.print("0 1");
return;
}
System.out.print("0 1 ");
while(--n >= 2) {
a3 = a0 + a1;
a0 = a1;
a1 = a3;
System.out.print(String.valueOf(a3) + " ");
}
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
name(in.nextInt());
in.close();
}
}