输入2 个正整数m和n(1<=m,n<=10000),输出m 和n之间所有的Fibonacci数。

2025-01-31 11:14:54
推荐回答(3个)
回答1:

import java.util.Scanner;

public class Test {
public static void main(String args[]) {
int ri, repeat;
int i, m, n;
long f;
Scanner in = new Scanner(System.in);
repeat = in.nextInt();
for (ri = 1; ri <= repeat; ri++) {
m = in.nextInt();
n = in.nextInt();
for (int j = 1;; j++) {
int fibJ=fib(j);
if (fibJ>n) {
break;
}
if (fibJ>=m) {
System.out.println(fibJ);
}

}
System.out.println();
}
}
public static int fib(int n) {
if (n==1||n==2) {
return 1;
}else {
return fib(n-1)+fib(n-2);
}
}
}

回答2:

m mmm,

回答3:

2