我现在很喜欢编程和学习java.我写了下面的代码但是我没有得到正确的结果: -
public class LifeTime {
public static void main(String[] args) {
int x;
for(x = 0; x < 3 ; x++); {
int y = -1; //y is initialized each time block is entered
System.out.println("y is : " + y); // this always prints -1
y = 100;
System.out.println("Y is : " + y);
}
}
}
Run Code Online (Sandbox Code Playgroud)
结果如下: -
y是:-1 Y是:100
直到3还有重复,为什么?
在我编写的所有循环程序中都观察到相同的行为
你能帮忙吗?