public class Main {
public static void main(String[] args) {
// 공식
//An = An-1 + An-2; n>=3
//처음 값을준다
int []arr = new int[100];
arr[1] = 1;
arr[2] = 1;
for (int i =3;i<100;i++){
arr[i] = arr[i-1]+arr[i-2];
}
for (int i=1; i<10;i++){
System.out.println(arr[i] + "");
}
//2번쨰 방법.
//An
//An = An-1 + An-2; n>=3
int prevPrevNum = 1; //An-2
int preNum = 1; //An-1
System.out.println(prevPrevNum+"111");
System.out.println(preNum+"2222222");
for (int i=3; i<10;i++){
int nNum = prevPrevNum+preNum;
System.out.println(nNum+"333");
preNum =nNum;
prevPrevNum = preNum;
}
}
}
결과 값
1
1
2
3
5
8
13
21
34