10/30自習

This commit is contained in:
2026-10-30 17:49:41 +09:00
parent d9529e2971
commit 0053058bfa
108 changed files with 1499 additions and 0 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,35 @@
import java.util.Random;
public class Question05_1 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
System.out.println("今日の運勢を占います。");
Random rand = new Random();
int num = rand.nextInt(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;
}
}
}

View File

@@ -0,0 +1,42 @@
import java.util.Scanner;
public class Question05_2 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
System.out.println("1つ目の数値を入力してください");
Scanner sca = new Scanner(System.in);
int num1 = sca.nextInt();
System.out.println("2つ目の数値を入力してください");
Scanner scb = new Scanner(System.in);
int num2 = scb.nextInt();
System.out.println("計算方法を選択してください");
Scanner scc = new Scanner(System.in);
int choice = scb.nextInt();
switch(choice) {
case 1:
System.out.println(num1 + num2);
break;
case 2:
System.out.println(num1 - num2);
break;
case 3:
System.out.println(num1 * num2);
break;
case 4:
System.out.println(num1 / num2);
break;
case 5:
System.out.println(num1 % num2);
break;
default:
System.out.println("計算に失敗しました");
}
}
}

View File

@@ -0,0 +1,67 @@
import java.util.Random;
import java.util.Scanner;
public class Question05_3 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
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("==========================================");
Random randd = new Random();
int dealerCard = randd.nextInt(13) + 1;
System.out.println("ディーラーのカードは" + dealerCard +"です");
Random randm = new Random();
int myCard = randm.nextInt(13) + 1;
System.out.println();
System.out.println("あなたのカードがディーラのカードより大きい場合は H 小さい場合は L を入力してください。");
System.out.println("※カードの数値が同じ場合はあなたの勝ちです。");
Scanner sc = new Scanner(System.in);
String judgement = sc.nextLine();
System.out.println("あなたのカードは" + myCard + "です");
System.out.println();
System.out.println("==========================================");
System.out.println("         勝敗判定         ");
System.out.println("==========================================");
switch (judgement) {
case "H":
if(dealerCard < myCard) {
System.out.println("あなたの勝ちです");
} else {
System.out.println("あなたの負けです");
break;
}
case "L" :
if(dealerCard > myCard) {
System.out.println("あなたの勝ちです");
} else {
System.out.println("あなたの負けです");
break;
}
default :
System.out.println("不正な値が入力されました");
};
}
}