调和级数的第n项形式为:1+1/2+1/3+…+1/n
class Exer1{
public static void main(String[] args) {
double sum = 0.0;
int i = 1;
while (true){
sum += 1.0/i;
if (sum > 10){
break;
}
i++;
}
System.out.println(i);
}
}
while(true)句型一定要注意
class Exer1{
public static void main(String[] args) {
double sum = 0.0;
int i = 1;
while (true){
sum += 1.0/i;
if (sum > 10){
break;
}
i++;
}
System.out.println(i);
}
}
while(true)句型一定要注意