my problem is to ensure that what the user types for the index of an array is really a digit and not a letter...please answer a.s.a.p. thx:D
how can I validate if what a user types is an integer or not
Collapse
X
-
In regard with your answer...how ill I know if the user typed a string value if it automatically converts it into an integer? Well the result I want to get is not an exception I just want to place the values in an if statement and if that statement states that they are not of equal data type...it will display a .setText message that I will indicate...Comment
-
Originally posted by kenrocksWell the result I want to get is not an exception I just want to place the values in an if statement and if that statement states that they are not of equal data type...it will display a .setText message that I will indicate...
action(s). The method does its part, you do the other part.
kind regards,
JosComment
-
Originally posted by kenrocksSo I have to try and catch? Can u teach me the basics of that methods
succesfully your String represented a number; if the 'catch' clause is executed
your String didn't represent a valid int number; it's some sort of an if-else structure. Look:
Code:String s= // your String value int value; // the result of the method try { value= Integer.parse(s); // here the String represented an int } catch (NumberFormatException nfe) { // here the String didn't represent an int }
JosComment
Comment