Allowing the User to input a number and assign this to an 'int' variable
I need the user to be able to input a number, and for the program to assign this value to an 'int' variable.
I know how to do this with a 'string' variable:
But I need to know how to do this with an 'int' variable. Thanks for your help!
String options = JOptionPane.showInputDialog(null, "In your decision, how many options do you have? \n" +
"(NOTE: The maximum number of options = 5, and you must enter your answer as a numeral.)");
Re: Allowing the User to input a number and assign this to an 'int' variable
You can parse the String to an int using the Integer.parseInt(String) method of the Integer class:
So, first as a string, then to an int.