【发布时间】:2016-04-28 21:38:23
【问题描述】:
我的代码有什么问题?当正确答案明显是 6,8 时,它会打印 2,2
public static void main(String[] args) {
int a = 1;
int b = 1;
int answer = 0;
int j = 4;
while (j == 4) {
for (a = 1; a <= 10; a++) {
for (b = 1; b <= 10; b++) {
answer = a * a + b * b;
if (answer == 100) {
j = 10;
}
}
}
}
System.out.println(a + " " + b);
}
【问题讨论】:
-
检查while循环是停止还是继续
-
为什么不只是
while(answer != 100)?
标签: java pythagorean