請有人解釋代碼的(「x =」+ x)部分。Java中的「+」運算符是做什麼的?
public class While-With-Nested-If {
public static void main(String [] args) {
int x = 1;
while(x < 100) {
System.out.println("x = " + x);
if(x % 2 == 0) {
x++;
} else {
x *= 2;
}
}
}
}
[「連接兩個字符串「](http://docs.oracle.com/javase/tutorial/java/data/strings.html) - 跟着一本書/教程,還有很多要學習的東西。 – user2864740 2014-09-06 06:49:00
[這是它的工作原理](http://codeinventions.blogspot.com/2014/08/compiler-version-string-concatenation.html) – 2014-09-06 06:50:14
您的班級名稱不是有效的標識符。因此'(「x =」+ x)'與代碼的其餘部分完全相同,即沒有(因爲它不編譯)。 – fabian 2014-09-06 10:15:21