【发布时间】:2023-04-05 18:54:01
【问题描述】:
我试图了解 Java 中递增的基础知识...这里有一个基本示例,但我不太清楚它的输出...所以它从 4 开始,当然是 2 * 2,和 9 是 4 * 4 + 1,但现在如何得到 16 呢?谢谢
public class Mystery
{
public static void main( String[] args )
{
int y;
int x = 2;
int total = 0;
while ( x <= 10 )
{
y = x * x;
System.out.println( y );
total += y;
++x;
}
System.out.printf( "Total is %d\n", total );
} // end main
} // end class Mystery
输出
4
9
16
25
36
49
64
81
100
Total is 384
【问题讨论】:
-
"9 等于 4 * 4 + 1" ????? 9 在这里是 3x3...
-
9 不是 4*4+1,是 3*3
-
你想在这里达到什么目的?
-
天哪,这就是我弄错了...我在看 y 而不是 x ..很好解决了这一切..谢谢
-
这是使用调试器单步调试代码有助于理解代码在做什么的地方。