62,614
社区成员
发帖
与我相关
我的任务
分享
int a=1,b=1,c;
for(i=3;i<=40;i++){
c=a+b;
a=b;
b=c;
}
System.out.println(c);
public static void recursive(int i, int j, int num) {
if (total <= num) {
total++;
if (total == num) {
System.out.println(i + j);
}
recursive(j, i + j, num);
}
}
public class Test {
public static void main(String[] args) throws Exception {
System.out.println(Test.circulate(40));
System.out.println(Test.recursive(40));
}
public static int circulate(int num) {
int value1 = 1;
int value2 = 1;
int temp = value1 + value2;
for (int i = 3; i <= num; i++) {
temp = value1 + value2;
value1 = value2;
value2 = temp;
}
return temp;
}
public static int recursive(int num) {
if (num > 2) {
return recursive(num - 1) + recursive(num - 2);
}
if (num <= 2) {
return 1;
}
return 0;
}
}
public class Test{
private int total =1;
private static int a = 0;
private static int b = 1;
public static void main(String[] args){
Test c = new Test();
c.calcMethod(a, b, 40);
}
public void calcMethod(int i, int j, int count) {
if(a==0){
System.out.println(1);
}
if (total <= count) {
b = i + j;
a = j;
total++;
System.out.println(b);
calcMethod(a, b, count);
}
}
}