私は数字を推測するゲームのアプリケーションを持っています。ユーザーは 0 から 100 までの数字を推測する必要があります。正しいと推測すると、プログラムは、プレイが終了したときにもう一度プレイするかどうかを尋ねます。ゲームでの推測の最小数を表示し、ゲームでの推測の最大数。今私が得るのは、「Math.min(,)」を使用するときのすべての推測の合計ですか? 最小限の機能を動作させるにはどうすればよいですか??? 関数コードはさらに下にあります。
leastNumGuesses = Math.min(leastNumGuesses,guesses);
double rightNum = Math.random() *100; int randomNum = (int) rightNum; //convert the random number to int int tries = 0; //single game gussess output int numberOfGames = 0; int allTries = 0; //accumalates all tries(sum of all tries) int guesses = 0; // guesses of all games combined int gameGuesses = 0; int leastNumGuesses = 100; int mostNumGuesses = 0; while (choice.equalsIgnoreCase("y"))
{
System.out.println(); int guess = getIntWithinRange(sc,"Enter the Number: ", 0, 100); tries++; guesses++; gameGuesses++; if (guess == randomNum) { numberOfGames++; System.out.println("You got it in " + tries + " tries."); leastNumGuesses = Math.min(leastNumGuesses,gameGuesses); if (tries <=3) System.out.println("Great work! You are a mathematical wizard."); else if (tries > 3 && tries <= 7) System.out.println("Not too bad! You've got some potential."); else if (tries > 7) System.out.println("What took you so long? Maybe you should take some lessons."); System.out.println(); System.out.println("Would you like to play again (y/n):"); choice = sc.nextLine(); while (!choice.equalsIgnoreCase("n") && !choice.equalsIgnoreCase("y")) { System.out.println("Error! entry must be \"y\" or \"n\"."); System.out.println("Would you like to play again (y/n):"); choice = sc.nextLine(); } if (choice.equalsIgnoreCase("y")) { // reset the random number & tries rightNum = Math.random() *100; randomNum = (int) rightNum; tries=0; gameGuesses++; } else if (choice.equalsIgnoreCase("n")) { allTries += guesses; int averageNumGuess = allTries / numberOfGames; System.out.println("Bye - Come back again"); System.out.println("Number of Games Played: " + numberOfGames); System.out.println("Average Number of Guesses: " + averageNumGuess); System.out.println("Least Amount of Guesses In a Single Game: " + leastNumGuesses); } }