This commit is contained in:
2026-09-11 14:44:53 +09:00
parent 5677614011
commit 43b7f458f3
5 changed files with 35 additions and 3 deletions

View File

@@ -17,6 +17,9 @@ public class PTra04_01 {
// TODO while文の条件を修正して5が出力されたら繰り返しを止めるようにしてください。
while(true) {
// 0~9のランダムな値を生成
if (randomNumber==5) {
break;
}
randomNumber = random.nextInt(10);
// 生成した値をコンソールに出力
System.out.println(randomNumber);

View File

@@ -15,6 +15,12 @@ public class PTra04_02 {
* 繰り返しの中でnumを2倍した数値をnumに代入してください。
* ※ 繰り返しにはwhile文を用いてください
*/
while(num <=1000) {
// num++;
num *=2;
System.out.println(num);
}
}
}

View File

@@ -18,6 +18,9 @@ public class PTra04_03 {
// ※ while文の条件は変更せずにbreak文を使ってください。
while(true) {
// 0~9のランダムな値を生成
if(randomNumber==5) {
break;
}
randomNumber = random.nextInt(10);
// 生成した値をコンソールに出力
System.out.println(randomNumber);

View File

@@ -1,3 +1,4 @@
/*
* PTra04_04.java
* 作成 Rhizome
@@ -18,13 +19,15 @@ public class PTra04_04 {
Random random = new Random();
// TODO 双六の総コマ数としてint型の変数mapを宣言し、50を代入してください。
int map =50;
// TODO 現在までの進んだコマ数としてint型の変数progressを宣言し、0を代入してください。
int progress = 0;
System.out.println("===== START =====");
// TODO 変数mapとprogressを用いて、ゴールするまで繰り返すようにwhile文の条件を記述してください。
while() {
while (progress < map) {
// 入力を促すメッセージを出力し、エンターキーが押されるのを待ちます。
System.out.println("Enterキーを押してください。さいころをふります。");
scanner.nextLine();
@@ -34,11 +37,16 @@ public class PTra04_04 {
// TODO 変数diceを用いて、"#の目が出ました。"というメッセージを出力してください。
// ※ #には変数diceの値が入ります。
System.out.println(progress+"の目が出ました");
// TODO 変数progressに変数diceの値を加算してください。
progress += dice;
// TODO まだゴールしていない場合は"残りのマスは#マスです。"というメッセージを出力してください。
// ※ #には双六の残りのマス数が入ります。
if (progress < map) {
System.out.println("残りのマスは"+(map - progress)+"マスです。");
}
}

View File

@@ -25,20 +25,32 @@ public class PTra04_05 {
int playerHand;
int npcHand;
// プレイヤーに出す手を選ばせる
// ※ 数値でない入力は考慮していません(エラーになります)
// ※ 数値でな い入力は考慮していません(エラーになります)
System.out.println("じゃんけんを行います。");
System.out.println("あなたの出す手を入力してください");
System.out.println("0:グー, 1:チョキ, 2:パー");
playerHand = Integer.parseInt(scanner.nextLine());
// TODO 選ばれた手を出力してください(0なら"あなたはグーを出しました"等)
String[]hand = {"グー", "チョキ", "パー"}; //for changing number to select for menume (menune arry[number array])
System.out.println("あなたは"+hand[playerHand] +"を出しました"); //here will be change number to menue
// 対戦相手の手をランダムに選択する。
npcHand = random.nextInt(3);
// TODO 対戦相手の手を出力してください(0なら"相手はグーを出しました"等)
System.out.println("相手は"+hand[npcHand]+"を出しました");
// TODO じゃんけんの結果を出力し、プレイヤーが勝った場合はプログラムが終了するようにしてください。
if (playerHand== npcHand) {
System.out.println("equal");
}else if ((playerHand==0 && npcHand==1)||(playerHand==2 && npcHand==0)||(playerHand==1&&npcHand==2)){
System.out.println("win");
winFlag= true;
}else {
System.out.println(("over"));
}
// 次のじゃんけんの前に改行しておく
System.out.println();