• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Java help: do all inputs using JOptionPane have to be strings?

I want to enter a number, but when I enter the number, can I set the entered number to be assigned to a double? Or do I have to use parseDouble()?
 
set the joptionpane to a string numberStr lets say. Then do this

number = Double.parseDouble(numberStr); That will convert to a double.
 
I haven't used Java in awhile, but I'm 95% sure that JOptionPane only accepts strings (thus if you need a double, you have to parse it). Look in Sun's docs if you want to be absolutely sure.
 
just do

double number;

number = Double.parseDouble(JOptionPane.showInputDialog(null, "blah"));

it'll do the JOptionPane and the parsing all in one line of code
 
Back
Top