Sevajper Sevajper - 11 days ago 10
Java Question

Character.IsDigit returns false instead of true on an integer Java

Hi I am newer to programming so I need some help. I need to make a method where I check if a birthday is correct. For instance 960214 where 96 is year 02 is month and 14 is day, but the birthday is a String. So here is what I got:

private static boolean checkCorrect(String a) {

int year = Integer.parseInt(a.substring(0,2));

int month = Integer.parseInt(a.substring(2, 4));

int day = Integer.parseInt(a.substring(4, 6));

if (a.length() == 6 && Character.isDigit(year)) {
return true;
} else
return false;
}


Now I stopped at Character.isDigit(year) because it returns false where it should return true. I printed year just to see what comes out and 96 comes out just like in the example on top. What am I doing wrong?

Answer

Character.isDigit(year) excepts a char not a number. Character.isDigit('5') this will return true.