私のプログラムの目標は、最初に1〜6の乱数を生成して「ポイント」と呼び、次にユーザーはキーを入力し続けて、並べられた「サイコロ」を再ロールすることです。同じ番号がロールされた場合、ユーザーは最初のifステートメントからのメッセージでプロンプトが表示されます
ただし、次のサイコロが振られるたびに、それがポイント番号に振られることはなく、最初のifステートメントの印刷行がランダムに印刷されます。これを修正する方法についての回答をいただければ幸いです。
import java.io.*;
public class DiceGame1
{
public static void main (String [] args) throws IOException
{
String userInput;
int DiceRoll;
int exit = 0;
BufferedReader myInput = new BufferedReader (new InputStreamReader (System.in));
System.out.println("Hello, this program rolls a dice and outputs the number rolled");
System.out.println("The number rolled is called the point it will keep rolling untill it");
System.out.println("hits that point again, press any key to con't");
userInput = myInput.readLine();
DiceRoll = (int) (Math.random () *(6-1) + 1);
System.out.println("The point to match is: " + DiceRoll);
System.out.println("Press any key to roll again...");
userInput = myInput.readLine();
while(exit != 999) {
int nextRoll = (int) (Math.random () *(6-1) + 1);
if (nextRoll == DiceRoll)
{
System.out.println(" It took the computer _____ tries to reach the point");
}
else
{
System.out.println("The roll is : " + nextRoll);
System.out.println("Press any key to roll again...Or press '999' to exit");
userInput = myInput.readLine();
}
}
}
}