diff --git a/Question05-switch/src/PTra05_01.java b/Question05-switch/src/PTra05_01.java index 60e8a86..363dde2 100644 --- a/Question05-switch/src/PTra05_01.java +++ b/Question05-switch/src/PTra05_01.java @@ -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; + } } } diff --git a/Question05-switch/src/PTra05_02.java b/Question05-switch/src/PTra05_02.java index 1b059ad..ef915e1 100644 --- a/Question05-switch/src/PTra05_02.java +++ b/Question05-switch/src/PTra05_02.java @@ -17,7 +17,10 @@ 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; + } } diff --git a/Question05-switch/src/PTra05_03.java b/Question05-switch/src/PTra05_03.java index 41cf99b..cefb96b 100644 --- a/Question05-switch/src/PTra05_03.java +++ b/Question05-switch/src/PTra05_03.java @@ -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; + + } + } } diff --git a/Question06-for/src/PTra06_01.java b/Question06-for/src/PTra06_01.java index cf38e18..86dcdfa 100644 --- a/Question06-for/src/PTra06_01.java +++ b/Question06-for/src/PTra06_01.java @@ -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); + } } } diff --git a/Question06-for/src/PTra06_02.java b/Question06-for/src/PTra06_02.java index e532445..f95c11d 100644 --- a/Question06-for/src/PTra06_02.java +++ b/Question06-for/src/PTra06_02.java @@ -10,6 +10,10 @@ public class PTra06_02 { /* * ■■■■■ */ + for(int i =0; i<6; i++) { + System.out.print("■"); + } + System.out.println(); } diff --git a/Question06-for/src/PTra06_03.java b/Question06-for/src/PTra06_03.java index 4386054..0e525b0 100644 --- a/Question06-for/src/PTra06_03.java +++ b/Question06-for/src/PTra06_03.java @@ -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); + + } } } diff --git a/Question06-for/src/PTra06_04.java b/Question06-for/src/PTra06_04.java index 8a947f3..a4b838b 100644 --- a/Question06-for/src/PTra06_04.java +++ b/Question06-for/src/PTra06_04.java @@ -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); + } } } diff --git a/Question06-for/src/PTra06_05.java b/Question06-for/src/PTra06_05.java index 191bbb0..9c42c4d 100644 --- a/Question06-for/src/PTra06_05.java +++ b/Question06-for/src/PTra06_05.java @@ -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); diff --git a/Question06-for/src/PTra06_06.java b/Question06-for/src/PTra06_06.java index 02b2f42..a1e7f2c 100644 --- a/Question06-for/src/PTra06_06.java +++ b/Question06-for/src/PTra06_06.java @@ -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("■"); + } } - + } diff --git a/Question06-for/src/PTra06_07.java b/Question06-for/src/PTra06_07.java index 149c022..6367470 100644 --- a/Question06-for/src/PTra06_07.java +++ b/Question06-for/src/PTra06_07.java @@ -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(); + + } + } } -} +