- 追加された行はこの色です。
- 削除された行はこの色です。
public class Hellows {
public static void main(String[] args) {
// for文
for (int i = 0; i < 5; i++) {
System.out.println("Hello World!");
}
// while文
int i = 0;
while (i < 5) {
System.out.println("Hello World!");
i++;
}
}
}
※コマンドラインからの入力分ループ
public class Hellows2 {
public static void main(String[] args) {
// コマンド入力から入力がない場合の例外処理
try {
int j = Integer.parseInt(args[0]);
for (int i = 0; i < j; i++) {
System.out.println("Hello World!");
}
} catch (ArrrayIndexOutOfBoundsException) {
System.out.println(" java Hello 1 のように実行してください");
}
}
}