这个才是正确的
public class Test {
public static void main(String args[]) {
float sum = 0;
for (int i = 1; i <= 999; i += 2) {
sum = sum + 1 / i;
}
System.out.println(sum);
}
}
import java.io.*;
class Test {
public static void main(String args[]) throws IOException {
int sum = 0;
for (int i = 1; i <= 999; i += 2) {
sum += i;
}
System.out.println(sum);
}
}
看看满意不!
long sum = 0;
for(int i=1;i<1000;i++){
if(i%2!=0){
sum += 1/i;
}
System.out.println("sum=" + sum);
}