public class Test4 {
public static void main(String[] args) {
int n;
int fn;
Scanner scanner=new Scanner(System.in);
System.err.println("请输入30以内的整数:");
n=scanner.nextInt();
fn=peibo(n);
System.out.println("斐波那契数列第"+n+"项为:"+fn);
}
public static int peibo(int n){
if(n==1 || n==2){
return 1;
}
// System.err.println(peibo(n-1)+peibo(n-2)+" n="+n);
return peibo(n-1)+peibo(n-2);
}
}
时间: 2024-10-11 12:57:46