Java教學
IanChang
18.5K views
Open Source Your Knowledge, Become a Contributor
Technology knowledge has to be shared and made accessible for free. Join the movement.
註解
我們將學習如何寫註解
註解就是對程式碼的解釋
註解是寫給其他人看的,所以電腦並不會執行
單行註解
單行註解的寫法是在註解開始的地方加入//符號
單行註解
1
2
3
4
5
6
7
8
9
10
11
12
//{
package com.yourself;
public class lesson2SingleComment {
public static void fun(){
//}
//這就是一個單行的註解
System.out.println("Hello Java"); //註解也可以寫在程式的後面
//{
}
}
//}
Press desired key combination and then press ENTER.
測驗
請你在程式碼裡加入一個寫著我愛Java
的註解
測驗
1
2
3
4
5
6
7
8
9
10
11
//{
package com.yourself;
public class lesson2SingleCommentExercise {
public static void fun() {
//}
//{
}
}
//}
Press desired key combination and then press ENTER.
多行註解
多行註解則是在開頭前加上/*
並在結尾後加上*/
多行註解
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//{
package com.yourself;
public class lesson2MultiComment {
public static void fun() {
//}
/*這就是
多行的註解
它可以有很多行(廢話!)*/
System.out.println("Java is cool!");
//{
}
}
//}
Press desired key combination and then press ENTER.
測驗
請你在程式碼裡加入多行註解,寫什麼都可以
測驗
1
2
3
4
5
6
7
8
9
10
11
//{
package com.yourself;
public class lesson2MultiCommentExercise {
public static void fun() {
//}
//{
}
}
//}
Press desired key combination and then press ENTER.
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content