How to check an input number?

Hi!Just want to know how I'm going to do to check that an input number is an int? And not a float, String etc.If the input number isn't an int, I want the program to shut down!/Mike
[211 byte] By [micottoa] at [2007-10-2 2:08:04]
# 1
Integer.parseInt() will throw an exception if the String it parses does not contain a parsable int.
stdunbara at 2007-7-15 19:49:31 > top of Java-index,Java Essentials,New To Java...
# 2
Ok, but if I want to write the "wrong messages" myself!
micottoa at 2007-7-15 19:49:31 > top of Java-index,Java Essentials,New To Java...
# 3

How about something like...

String inputString;

// read into inputString somehow

int value;

try {

value = Integer.parseInt( inputString );

} catch( NumberFormatException nfe ) {

System.err.println( "the inputString does not contain an integer" );

}

stdunbara at 2007-7-15 19:49:31 > top of Java-index,Java Essentials,New To Java...
# 4
look here http://java.sun.com/developer/JDCTechTips/2001/tt1120.htmlfor validating the input in a text field
kris.richardsa at 2007-7-15 19:49:31 > top of Java-index,Java Essentials,New To Java...