This commit is contained in:
2026-09-11 16:34:54 +09:00
parent 43b7f458f3
commit c0fd62c0d8
10 changed files with 114 additions and 6 deletions

View File

@@ -11,7 +11,6 @@ public class PTra05_01 {
// ランダムな数値をnumに代入します。範囲は 0 ~ 5 です。
int num = new java.util.Random().nextInt(6);
// TODO 以下の条件に沿ったプログラムを記述してください
// ※ switch文を使用してプログラムを記述してください
/*
@@ -23,5 +22,28 @@ public class PTra05_01 {
* 変数numの値が 4 の場合 -> あなたの運勢は「末吉」です
* 変数numの値が 5 の場合 -> あなたの運勢は「凶」です
*/
System.out.println(num);
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("あなたの運勢は「凶」です");
default:
break;
}
}
}

View File

@@ -17,8 +17,11 @@ public class PTra05_02 {
System.out.println("計算方法を選択してください");
// キーボードから入力した文字列を choice に代入します。
System.out.println("");
String choice = new java.util.Scanner(System.in).nextLine();
String[]result = {"+","-","*","/","%"};
// TODO 以下の条件に沿ったプログラムを記述してください
/*
* 入力された数値によって以下のように出力してください。
@@ -29,6 +32,25 @@ public class PTra05_02 {
* 変数choiceの値が % の場合 -> num1 を num2 で 割った余り を出力
* 変数choiceの値が 上記以外 の場合 -> 計算に失敗しました を出力
*/
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:
break;
}
}

View File

@@ -34,7 +34,7 @@ public class PTra05_03 {
String judgement = new java.util.Scanner(System.in).nextLine();
System.out.println("あなたのカードは" + myCard + "です");
// System.out.println("ディーラのカードは" + dealerCard + "です。");
System.out.println();
System.out.println("=========================================");
System.out.println(" 勝敗判定");
@@ -43,5 +43,28 @@ public class PTra05_03 {
// TODO 予想が当たった場合は「あなたの勝ちです」、外れた場合は「あなたの負けです」を出力してください。
// ※ H か L 以外の文字が入力された場合は、「不正な値が入力されました」と出力してください。
switch (judgement) {
case "H":
case "h":
if (myCard >= dealerCard) {
System.out.println("あなたの勝ちです");
} else {
System.out.println("あなたの負けです");
}
break;
case "L":
case "l":
if (myCard <= dealerCard) {
System.out.println("あなたの勝ちです");
} else {
System.out.println("あなたの負けです");
}
break;
default:
System.out.println("不正な値が入力されました");
break;
}
}
}

View File

@@ -7,6 +7,8 @@
public class PTra06_01 {
public static void main(String[] args) {
// TODO for文を使って0から99までの整数を順にコンソールに出力してください。
for (int i = 0; i < 100; i++) {
System.out.println(i);
}
}
}

View File

@@ -10,6 +10,10 @@ public class PTra06_02 {
/*
* ■■■■■
*/
for(int i =0; i<6; i++) {
System.out.print("■");
}
System.out.println();
}

View File

@@ -11,6 +11,10 @@ public class PTra06_03 {
for (int i = 0; i <= 100; i++) {
// TODO iが偶数の時だけ、iの値を出力してください
if(i%2==0) {
System.out.println(i);
}
}
}

View File

@@ -14,7 +14,17 @@ public class PTra06_04 {
* ④ 上記のいずれにも当てはまらない場合はiの値をそのまま出力する
*/
for(int i = 1;i < 50;i++) {
if ((i%3==0)&&(i%5==0)) {
System.out.println("fizzbuzzzzzzzzzzzzz");
}else if(i%3==0) {
System.out.println("fizz");
}else if(i%5==0) {
System.out.println("buzz");
}else {
System.out.println(i);
}
}
}

View File

@@ -18,6 +18,10 @@ public class PTra06_05 {
// ※ continueを用いてください。
for(int i = 0;i < 10;i++) {
randomNumber = random.nextInt(3);
if(randomNumber==2) {
continue;
}
System.out.println(randomNumber);

View File

@@ -15,6 +15,13 @@ public class PTra06_06 {
* ■■■■■
*/
for (int i=0; i<5;i++ ){
for(int r=0; r<4;r++) {
System.out.print("■");}
System.out.println("■");
}
}
}

View File

@@ -19,7 +19,17 @@ public class PTra06_07 {
* 8 16 24 32 40 48 56 64 72
* 9 18 27 36 45 54 63 72 81
*/
for (int i=1; i<=9;i++ ){
for(int r=1; r<=9;r++) {
System.out.print(i*r + " ");
}
System.out.println();
}
}
}