日期:2014-05-20 浏览次数:20554 次
private static int num=30;
public static void main(String[] args) {
int a0=0;
int a1=1;
show(a0, a1,num);
}
public static int show(int x,int y,int num){
if(num>=0){
int z = show(y, x+y, --num);
return z;
}else{
System.out.println(x+y);
return 0;
}
}
public class jiajia {
public static void main(String[] args) {
int a = 1, b = 1;
for (int i = 1; i <30; i++) {
b += a;
a = b - a;
}
System.out.println(a);
}
}
package com.test;
import java.util.ArrayList;
import java.util.List;
/**
* //a0=1 a1=1 a2=a0+a1 a3=a2+a1 a4=a3+a2 a5=a4+a3 a6=a5+a4 a7=a6+a5 a30=a29+a28
* @author gp
*/
public class Test {
static int num = 0;// 计数器
static int result = 0; // 结果
static List<Integer> list = new ArrayList<Integer>();
public static void main(String[] args) {
int a = 30;
test(a);
System.out.println("a"+a+" = " + list.get(num - 1));
}
/**
* 通过递归进行计算
* @param value
*/
public static void test(int value){
while(value > num){
if(num == 0){
list.add(1);
} else if(num == 1){
list.add(2);
} else {
list.add(list.get(num - 1) + list.get(num - 2));
}
num++;
test(value);
}
}
}