This commit is contained in:
2026-10-19 13:50:48 +09:00
parent 2c6d1574e5
commit 0cc90c94a3
95 changed files with 1505 additions and 2 deletions

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21"/>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="output" path="build/classes"/>
</classpath>

1
Question05-switch/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/build/

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Question05-switch</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@@ -0,0 +1,9 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21
org.eclipse.jdt.core.compiler.compliance=21
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=21

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<installed facet="java" version="21"/>
</faceted-project>

View File

@@ -0,0 +1,23 @@
import java.util.Random;
public class Question5_1 {
public static void main(String[] args) {
System.out.println("今日の運勢を占います。");
String[] omikuji = {"大吉", "吉", "中吉", "小吉", "末吉", "凶"};
Random random = new Random();
int num = random.nextInt(6);
switch (num) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
System.out.println("あなたの運勢は「" + omikuji[num] + "」です");
break;
}
}
}

View File

@@ -0,0 +1,44 @@
import java.util.Scanner;
public class Question5_2 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
Scanner scan = new Scanner(System.in);
System.out.println("1つ目の数値を入力してください");
int num1 = scan.nextInt();
System.out.println("2つ目の数値を入力してください");
int num2 = scan.nextInt();
System.out.println("計算方法を選択してください");
String choice = scan.next();
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("計算に失敗しました");
}
scan.close();
}
}

View File

@@ -0,0 +1,67 @@
import java.util.Random;
import java.util.Scanner;
public class Question5_3 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
Scanner scanner = new Scanner(System.in);
Random random = new Random();
System.out.println("=========================================");
System.out.println(" ゲームの説明");
System.out.println("=========================================");
System.out.println("これからハイ&ローゲームを行います。");
System.out.println("ハイ&ローゲームは、あなたのカードがディーラーのカードより大きいか小さいかを予想するゲームです。");
System.out.println();
System.out.println("=========================================");
System.out.println(" ゲーム開始");
System.out.println("=========================================");
System.out.println();
// ディーラーのカード
int dealerCard = random.nextInt(13) + 1;
System.out.println("ディーラーのカードは" + dealerCard + "です");
// 自分のカード
int myCard = random.nextInt(13) + 1;
System.out.println();
System.out.println("あなたのカードがディーラのカードより大きい場合は H 小さい場合は L を入力してください。");
System.out.println("※ カードの数値が同じ場合はあなたの勝ちです。");
String judgement = scanner.nextLine();
System.out.println("あなたのカードは" + myCard + "です");
System.out.println();
System.out.println("=========================================");
System.out.println(" 勝敗判定");
System.out.println("=========================================");
System.out.println();
switch (judgement) {
case "H":
if (myCard >= dealerCard) {
System.out.println("あなたの勝ちです");
} else {
System.out.println("あなたの負けです");
}
break;
case "L":
if (myCard == dealerCard || myCard < dealerCard) {
System.out.println("あなたの勝ちです");
} else {
System.out.println("あなたの負けです");
}
break;
default:
System.out.println("不正な値が入力されました");
}
scanner.close();
}
}