JOptionPane Input to int

前端 未结 5 1512
面向向阳花
面向向阳花 2021-01-02 14:31

I am trying to make a JOptionPane get an input and assign it to an int but I am getting some problems with the variable types.

I am trying something like this:

5条回答
  •  别那么骄傲
    2021-01-02 15:15

    This because the input that the user inserts into the JOptionPane is a String and it is stored and returned as a String.

    Java cannot convert between strings and number by itself, you have to use specific functions, just use:

    int ans = Integer.parseInt(JOptionPane.showInputDialog(...))
    

提交回复
热议问题