CodeGym /課程 /Java 語法 /print() 和 println();

print() 和 println();

Java 語法
等級 1, 課堂 7
開放

「嗨,又是我。今天我會跟你一起上三堂課。這是第二堂!找個舒服的姿勢,仔細聽好。我會告訴你怎麼在螢幕上顯示文字。這其實很簡單:」

Java 代碼 顯示在螢幕上的結果
System.out.println("Diego");
System.out.println(3);
System.out.println("Rain" + "In" + "Spain");
Diego
3
RainInSpain
System.out.println(1 + 3);
System.out.println("1" + "3");
System.out.println(1 + "3");
System.out.println("1" + 3);
System.out.println("1" + (1 + 3));
4
13
13
13
14
System.out.println("Amigo is the best!");
System.out.println("Amigo" + "is the best!");
System.out.println("Amigo" + " " + "is the best!");
Amigo is the best!
Amigois the best!
Amigo is the best!
System.out.println(3 * 3 + 4 * 4);
System.out.println(1 * 2 + 3 * 4);
25
14
System.out.print("Diego");
System.out.print("Diego");
System.out.print("Diego");
DiegoDiegoDiego
System.out.print("Diego ");
System.out.println("is the best!");
System.out.print("Amigo ");
System.out.println("is the best!");
Diego is the best!
Amigo is the best!
1
任務
Java 語法, 等級 1, 課堂 7
上鎖
找到臭蟲
找到臭蟲

「你可以再說一下 print() 和 println() 嗎?」

「 print() 函式是用來在螢幕上顯示文字的,一個字接著一個字。當螢幕上的一行擠滿了,沒有空間,文字就會從下一行開始顯示。但在滿了以前,你可以用 println() 函式,停止文字繼續顯示在目前這行。之後的文字會從下一行開始出現。」

「OK。那把數字跟字串加在一起是什麼花招?」

「如果你把兩個數字加在一起,結果還是一個數字:2+2 等於 4。如果你把一個數字跟一個字串加在一起,數字會被轉換成字串。然後這兩個字串會被接在一起。」

「喔!我看到範例的時候就是這樣想的,誰知道就是這樣。謝謝你這堂有趣的課,艾莉。」

「不客氣。最後,這裡有一些迪亞哥給的任務。他想要確認你的進步程度。」

1
任務
Java 語法, 等級 1, 課堂 7
上鎖
我們不需要多餘的代碼
我們不需要多餘的代碼
1
任務
Java 語法, 等級 1, 課堂 7
上鎖
Code entry
Sometimes you don't need to think, you just need to hammer it out! As paradoxical as it may seem, sometimes your fingers will "remember" better than your conscious mind. That's why while training at the secret CodeGym center you will sometimes encounter tasks that require you to enter code. By entering code, you get used to the syntax and earn a little dark matter. What's more, you combat laziness!
留言
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION