這是我的代碼:的println不打印預期值
public static void main(String[] arg)
{
String x = null;
String y = "10";
String z = "20";
System.out.println("This my first out put "+x==null?y:z);
x = "15";
System.out.println("This my second out put "+x==null?y:z);
}
我的輸出是:
20
20
但我很期待這樣的:
This my first out put 10
This my second out put 20
有人能解釋我爲什麼爲這兩個println調用輸出「20」作爲輸出?
Sumit Singh的回答解釋了爲什麼輸出是這樣的。原因是運算符優先級,請參閱[本文檔](http://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html) – jlordo
@coders我接受 – Suranga