为什么以下工作正常?
String str;
while (condition) {
str = calculateStr();
.....
}
Run Code Online (Sandbox Code Playgroud)
但据说这个是危险的/不正确的:
while (condition) {
String str = calculateStr();
.....
}
Run Code Online (Sandbox Code Playgroud)
是否有必要在循环外声明变量?
你能解释一下这个Java代码的输出吗?
int a=5,i;
i=++a + ++a + a++;
i=a++ + ++a + ++a;
a=++a + ++a + a++;
System.out.println(a);
System.out.println(i);
Run Code Online (Sandbox Code Playgroud)
两种情况下的输出均为20