public class Demo {
public static int f(int n) throws Exception {
if(n==0){
throw new Exception("参数错误!");
}
if (n == 1 || n == 2) {
return 1;
} else {
return f(n-1)+f(n-2);//自己调用自己
}
}
public static void main(String[] args) throws Exception {
for (int i = 1; i <=10; i++) {
System.out.print(f(i)+" ");
}
}
}