Test if char is '0'-'9' [migrated]
- by Chris Okyen
My Java code is
// if the first character is not 0-9
if(
(((input.substring(0,0)).compareTo("1")) < 0 || (((input.substring(0,0)).compareTo("9")) < 0));
{
System.out.println("Error: The first digit of the temperature is not 1-9. Force Exiting Program. ");
System.exit(1); // exit the program
}
But it slips through even with input like '1123' or '912' or '222', and gives this error message. Whether I have it 0 for first and < 0 for the second, or 0 and 0, or < 0 and < 0, or even < o and 0... How come?