close
/*試撰寫一程式,計算
1 1 1
2 3 10
1+ + +L+ 的總和(輸出值請用浮點數)。
*/
public class P5_3_23 {
public static void main(String[] args) {
double x=0;
int z=2;
double sum=0;
while(z<=10){
x=x+1.0/z;
System.out.println(x+1);
z++;
}
/*
1.5
1.8333333333333333
2.083333333333333
2.283333333333333
2.45
2.5928571428571425
2.7178571428571425
2.828968253968254
2.9289682539682538
*/
文章標籤
全站熱搜