Search code examples
javaswingjoptionpane

Is there a way to convert a string to a double or int in one statement inside of a JOptionPane?


I'm new to Java and the site. First off, thanks for any input, I appreciate it.

So, for a homework assignment, I am asked to use dialog input and convert it to a double in one statement. I have been searching my text and the web for hours to no avail. Would someone so kindly direct me, PLEASE? I don't want the answer, just a direction, thanks!


Solution

  • double inputNum = Double.parseDouble(JOptionPane.showInputDialog(null, "Enter number"));
    

    or for int:

    int inputNum = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter number"));
    

    Often consulting the API can answer many questions.