-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathArray5.java
More file actions
32 lines (28 loc) · 742 Bytes
/
Array5.java
File metadata and controls
32 lines (28 loc) · 742 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
package array;
public class Array5 {
public static void main(String[] args) {
solution(5);
System.out.println();
solution(10);
System.out.println();
solution(20);
System.out.println();
solution(30);
System.out.println();
solution(40);
}
// n ta fibonachi sonlari bilan to'ldiring
// 1 1 2 3 5 8 13 21 34 ...
// 5
public static void solution(int n) {
int[] fib = new int[n];
fib[0] = 1;
fib[1] = 1;
for (int i = 2; i < n; i++) {
fib[i] = fib[i - 1] + fib[i - 2]; // 1 1 2 3 5 8 13 ....
}
for (int i = 0; i < n; i++) {
System.out.print(fib[i] + "\t");
}
}
}