//本篇给出了斐波那契数列的打印方法和在输入最大数时,打印最大值以下的数列方法。
import java.util.Scanner;
public class Fbnq{
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.print(“请输入一个最大数:”);
int Max = s.nextInt();
int a=1;
int b=1;
int c=0;
System.out.print(a+" “+b+” “);
while(c<Max){
c=a+b;
a=b;
b=c;
if(c<Max){
System.out.print(c+” ");
}
}
}
}
斐波那契数列给定最大值
最新推荐文章于 2022-08-01 21:00:00 发布