它打印輸出從case 10:
但打印x=11
如何?之後一行它增加x
增量操作員如何在開關櫃中工作?
int x = 10;
switch (x++) {
case 10:
System.out.println("case 1 ::: "+x);
break;
case 11:
System.out.println("case 2 ::: "+x);
break;
default:
System.out.println("default ::: "+x);
}
輸出
case 1 ::: 11
增量操作符它以同樣的方式在所有其他聲明。它對於'switch'語句行爲不同。 – Andreas
首先使用x的值爲10,然後遞增,之後增量爲11,以便更好地理解讀後增量器和增量器 – dhS
遞增運算符在Java教程http:// docs中進行了說明。 oracle.com/javase/tutorial/java/nutsandbolts/op1.html。閱讀精細手冊。 –