1 package FushiExam; 2 3 public class Text_20 { 4 5 public static void main(String[] args) { 6 /* 7 * 计算2/1,3/2,5/3,8/5,13/8,21/13....前20项之和 8 */ 9 double sum=0; 10 double first=2,second=1,t; 11 for(int x=0;x<20;x++) { 12 sum=sum+first/second; 13 t=second; 14 second=first; 15 first=t+second; 16 } 17 System.out.println("2/1+3/2+5/3+...前20项之和是:"+sum); 18 19 } 20 21 }