java :递归
2016-01-21 本文已影响75人
冰J冰
public class BRRead {
public static void main(String args[])
{
System.out.print(f(30));
}
public static int f(int x){
if (x == 1 || x == 2) {
return 1;
}else{
return f(x-1) + f(x-2);
}
}
}
f(x) = f(x-1)+f(x-2); x>=3;
f(1) = 1;
f(2) = 1;