これまでのところ、
package randomnumberguessinggame;
import java.util.Scanner;
public class RandomNumberGuessingGame {
public static void main(String[] args) {
int secretNumber;
secretNumber = (int) (Math.random() * 999 + 1);
Scanner keyboard = new Scanner(System.in);
int guess;
int count = 0;
do {
System.out.print("Enter a guess: (1-1000) ");
guess = keyboard.nextInt();
System.out.println("Your guess is " + guess);
if (guess == secretNumber)
System.out.println("Your guess is correct. Congratulations!");
else if (guess < secretNumber)
System.out.println("Your guess is smaller than the secret number.");
else if (guess > secretNumber)
System.out.println("Your guess is greater than the secret number.");
} while (guess != secretNumber);
}
}
このコードは機能しますが、ユーザー入力の数を数える方法を知る必要があります。前もって感謝します。