My assignment is to create a randomly generated number, ask the user to enter a number, then compare the two and show a messagebox telling whether or not they match. This is my code so far...
import javax.swing.*; //GUI components
public class RandomGuessMatch {
public static void main(String[] args) {
Integer random = (1 + (int)(Math.random() * 5)),
userNum;
// Get the input
userNum = JOptionPane.showInputDialog("Enter a number 1 - 5.");
//Checks to see if numbers match
boolean matches = (random == userNum);
JOptionPane.showMessageDialog(null, "The random number is " + random + ". " + "Does it match? " + matches);
}
}
The only error I'm getting is when I'm trying to get the user input. "Cannot convert from String to Integer". But, I'm having trouble figuring out how to just get the user's number and correlate it to "userNum" so that I can compare it with "random". Any help?