回答編集履歴

1

値が 40以下のコードを追加

2020/07/17 19:40

投稿

kazuma-s
kazuma-s

スコア8224

test CHANGED
@@ -21,3 +21,39 @@
21
21
  }
22
22
 
23
23
  ```
24
+
25
+ **追記**
26
+
27
+ ```Java
28
+
29
+ class Test {
30
+
31
+ static final int N = 40;
32
+
33
+
34
+
35
+ public static void main(String[] args) {
36
+
37
+ int[] a = new int[N + 2];
38
+
39
+ a[1] = 1;
40
+
41
+ int n;
42
+
43
+ for (n = 2; n < a.length; n++) {
44
+
45
+ a[n] = a[n-1] + a[n-2];
46
+
47
+ if (a[n] > N) break;
48
+
49
+ }
50
+
51
+ for (int i = 1; i < n; i++)
52
+
53
+ System.out.println("fibonacci(" + i + ") = " +a[i]);
54
+
55
+ }
56
+
57
+ }
58
+
59
+ ```