在这段代码中:
public class PiCalc {
public static void main(String[] args) {
double pi = 1.0;
int n = 3;
int denominator = 3;
while (n<10) {
if (n%2 == 0) {
pi += 1/denominator;
}
else {
pi -= 1/denominator;
}
n++;
denominator += 2;
}
System.out.println(4*pi + "," + n + "," + denominator);
}
}
输出为:4.0,10,17
因此,变量 n 和分母正在按我的意愿更新,但 pi 不是。谁能告诉我为什么?