public class Fib {
static int a = 0;
static int b = 1;
static int index = 0;
static int number;
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
System.out.println("请输入所要求的月份的兔子:");
number = (int)sc.nextDouble();
if(number<=0) {
System.out.println("输入有误,请重新输入正整数");
return;
}
f(0);
}
public static void f(int n) {
a = b;
b = n;
index++;
System.out.print((a + b) + " ");
if (number == index) {
return;
}
f(a + b);
}
}
|