System.out.println(1 + 2 + "3");
Run Code Online (Sandbox Code Playgroud)
产量:33
System.out.println("1" + 2 + 3);
Run Code Online (Sandbox Code Playgroud)
输出:123
int a = 1, b;
if(a > 0) b = 1;
if(a <= 0) b = 2;
System.out.println(b);
Run Code Online (Sandbox Code Playgroud)
如果我运行这个,我收到:
Exception in thread "main" java.lang.Error: Unresolved compilation problem: The local variable b may not have been initialized at Broom.main(Broom.java:9)
我知道局部变量没有初始化,你有责任这样做,但在这种情况下,第一个if不初始化变量?
java variables compiler-errors initialization variable-assignment