練習問題
This commit is contained in:
40
Question05-switch/src/main/java/Q5_1.java
Normal file
40
Question05-switch/src/main/java/Q5_1.java
Normal file
@@ -0,0 +1,40 @@
|
||||
|
||||
public class Q5_1 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
int num;
|
||||
System.out.println("今日の運勢を占います");
|
||||
|
||||
num = (int)(Math.random() * 6);
|
||||
|
||||
switch(num){
|
||||
|
||||
case 0:
|
||||
System.out.println("あなたの運勢は「大吉」です");
|
||||
break;
|
||||
|
||||
case 1:
|
||||
System.out.println("あなたの運勢は「吉」です");
|
||||
break;
|
||||
|
||||
case 2:
|
||||
System.out.println("あなたの運勢は「中吉」です");
|
||||
break;
|
||||
|
||||
case 3:
|
||||
System.out.println("あなたの運勢は「小吉」です");
|
||||
break;
|
||||
|
||||
case 4:
|
||||
System.out.println("あなたの運勢は「末吉」です");
|
||||
break;
|
||||
|
||||
case 5:
|
||||
System.out.println("あなたの運勢は「凶」です");
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
51
Question05-switch/src/main/java/Q5_2.java
Normal file
51
Question05-switch/src/main/java/Q5_2.java
Normal file
@@ -0,0 +1,51 @@
|
||||
import java.util.Scanner;
|
||||
public class Q5_2 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
|
||||
Scanner sc = new Scanner(System.in);
|
||||
|
||||
System.out.println("1つ目の数値を入力してください");
|
||||
int num1 = sc.nextInt();
|
||||
|
||||
|
||||
System.out.println("2つ目の数値を入力してください");
|
||||
int num2 = sc.nextInt();
|
||||
|
||||
|
||||
System.out.println("計算方法を選択してください");
|
||||
String choice = sc.next();
|
||||
|
||||
sc.close();
|
||||
|
||||
switch (choice) {
|
||||
|
||||
case "+":
|
||||
System.out.println((num1 + num2));
|
||||
break;
|
||||
|
||||
case "-":
|
||||
System.out.println((num1 - num2));
|
||||
break;
|
||||
|
||||
case "*":
|
||||
System.out.println((num1 * num2));
|
||||
break;
|
||||
|
||||
case "/":
|
||||
System.out.println((num1 / num2));
|
||||
break;
|
||||
|
||||
case "%":
|
||||
System.out.println((num1 % num2));
|
||||
break;
|
||||
|
||||
default:
|
||||
System.out.println("計算に失敗しました");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user