PDA

View Full Version : JOptionPane works with double but how do I make it work with int?



s3a
September 8th, 2009, 03:37 AM
The following is a sample piece of code I have:


import javax.swing.JOptionPane;

public class If

{
public static void main (String [] args)

{
double number;
String input;

input = JOptionPane.showInputDialog("Enter a number");
number = Double.parseDouble(input);

if (number >= 5.0)
JOptionPane.showMessageDialog(null, "Big");

if (number < 5.0)
JOptionPane.showMessageDialog(null, "Small");

System.exit(0);

}
}

Why doesn't this work and how can I make it work?:


import javax.swing.JOptionPane;

public class If

{
public static void main (String [] args)

{
int number;
String input;

input = JOptionPane.showInputDialog("Enter a number");
number = Int.parseInt(input);

if (number >= 5.0)
JOptionPane.showMessageDialog(null, "Big");

if (number < 5.0)
JOptionPane.showMessageDialog(null, "Small");

System.exit(0);

}
}

baizon
September 8th, 2009, 08:25 AM
Read this:
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Integer.html#parseInt%28java.lang.String,%20int%29