这个思想差不多。
public class SuLie {
public static void main(String[] args) {// TODO Auto-generated method stubdouble a = 2.0;double b = 1.0;double c;double sum = 0.0;for (int i = 1; i <= 20; i++) {sum += a / b;c = b;b = a;a = a + c;}System.out.PRintln("前20项之和:" + sum);}}
递归算法实现
public class DiGui {public static void main(String[] args) {// TODO Auto-generated method stubSystem.out.print(sum(7) + ",");}public static int sum(int n) {if (n == 0) {return 0;} else if (n == 1) {return 1;} else {return sum(n - 1) + sum(n - 2);}}}
新闻热点
疑难解答