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

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!