public class day4_3{
public static void main(String[] args ){
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int i = 1,j = 2,temp=0;
double sum = 0.0;
for( int t = 1;t < n;t++){
System.out.println(j*1.0/i);
temp = i;
i = j;
j += temp;
sum += j*1.0/i;
}
System.out.println("前"+n+"项之和为:"+sum);
}
}
这个应该可以 你试试
|