練習問題
This commit is contained in:
12
Question03-if/src/main/java/Q3_1.java
Normal file
12
Question03-if/src/main/java/Q3_1.java
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
public class Q3_1 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
int num;
|
||||
num = 100;
|
||||
if(num == 100);
|
||||
System.out.println("条件に合致しました");
|
||||
}
|
||||
|
||||
}
|
||||
14
Question03-if/src/main/java/Q3_2.java
Normal file
14
Question03-if/src/main/java/Q3_2.java
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
public class Q3_2 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
int num = 65;
|
||||
|
||||
if (num >= 65) {
|
||||
System.out.println("合格です");
|
||||
} else {
|
||||
System.out.println("不合格です");
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Question03-if/src/main/java/Q3_3.java
Normal file
12
Question03-if/src/main/java/Q3_3.java
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
public class Q3_3 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
int num = 10;
|
||||
if (num % 2 == 0 && num % 5 == 0) {
|
||||
System.out.println(num + "10は2でも5でも割り切れます。");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
36
Question03-if/src/main/java/Q3_4.java
Normal file
36
Question03-if/src/main/java/Q3_4.java
Normal file
@@ -0,0 +1,36 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Q3_4 {
|
||||
public static void main(String[] args) {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
int num;
|
||||
|
||||
|
||||
System.out.print("降水確率を入力してください。(数字のみ): ");
|
||||
|
||||
if (!scanner.hasNextInt()) {
|
||||
System.out.println("エラー: 数字を入力してください。");
|
||||
scanner.close();
|
||||
return;
|
||||
}
|
||||
|
||||
num = scanner.nextInt();
|
||||
|
||||
if (num < 0 || num > 100) {
|
||||
System.out.println("不正な値が入力されました");
|
||||
scanner.close();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (num >= 75) {
|
||||
System.out.println("雨が降る確率が高いです");
|
||||
} else if (num >= 30) {
|
||||
System.out.println("雨が降るかもしれないです");
|
||||
} else {
|
||||
System.out.println("雨はまず降らないでしょう");
|
||||
}
|
||||
|
||||
scanner.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user