Answer:
import javax.swing.JOptionPane;
public class RandomGuess {
public static void main(String[] args) {
String guessString = JOptionPane.showInputDialog(null, "Think of a number between 1 and 10");
int guess = Integer.parseInt(guessString);
int random = 1 + (int)(Math.random() * 10);
JOptionPane.showMessageDialog(null, "Your guess was " + guess + "\\The number was " + random + "\\" + (guess == random ? "You guessed it!" : "Better luck next time."));
}
}
Step-by-step explanation:
This program prompts the user to think of a number between 1 and 10, then generates a random number in the same range and displays it in a dialog box along with the user's guess. If the guess matches the random number, the program displays a "You guessed it!" message; otherwise, it displays a "Better luck next time" message.