//10. 求得斐波那契数列前20项的值并输出。
public class Demo10{
public static void main(String[] args){
//两个默认值: 1 1
//规则:当前项的值 等于前两项值的和
int first = 1;
int second = 1;
for(int i = 1;i<=20;i++){
int next = first + second;
System.out.println(next);
first = second;
second = next;
}
}
}
网友评论