728x90
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
61
|
import java.util.Arrays;
public class pibonaci {
public static void main(String[] args) {
// 피보나치 수열이다
// 1항 : 1
// 2항: 1
// 3항 : 1항 + 2항
// 4항 : 2항 + 3항
/*
int num1 = 0;//초기화
int num2 = 1;
int sum = 1;
for(int i = 0; i < 10; i++) {
sum=num1+num2; // 두 값을 더한 후
num1=num2;
num2=sum;
System.out.println(" " + sum);
}
*/
//0 1 1 2
long a, b, c;
long arrNum[] = new long[30];
a = 0;
b = 1;
arrNum[0] = a;
arrNum[1] = b;
int w = 0;
while(w<28) {
c = a+b;
arrNum[w + 2] = c;
a = b;
b = c; //한칸씩 밀린다
w++;
}
System.out.println(Arrays.toString(arrNum));
}
}
|
cs |
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229]
728x90
'JAVA' 카테고리의 다른 글
8일차//[java] 두점 간의 거리를 구하라 (메소드 사용) (0) | 2021.01.21 |
---|---|
8일차//[JAVA] sorting(정렬) 오름차순, 내림차순/데이터를 받아 숫자몇개를 정렬할지~? (0) | 2021.01.20 |
7일차//[JAVA] 2차원배열, 학생 성적 입력 (2)- > 합계, 평균 출력 (0) | 2021.01.20 |
자바의 핵심 - 객체지향 프로그래밍(클래스와 객체)1-method (0) | 2021.01.20 |
8일차//[JAVA] 배열 sorting(정렬) 오름차순, 내림차순 (0) | 2021.01.20 |