这个题目的算法,应该自己能想出来的,这题比较简单。 除非是个傻子,正常人都应该10分钟内想出来。
得出的结果是:
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,832040,
public static void main(String[] args) {
int n1=1;
int n2=1;
System.out.print("1,1,");
for(int i=3;i<=30;i++){
int temp=n1;
n1=n1+n2;
n2=temp;
System.out.print(n1+",");
}
}
得出的结果是:
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,832040,