how-to

Working with Char

How to check if character is number

When you have a char and you need to detect if it is a digit, use this code:

if ( Character.isDigit( '5' ) ) System.out.println( "5 " + "is digit");
  else System.out.println( "5 " + "is not digit");

if ( Character.isDigit( 'x' ) ) System.out.println( "x " + "is digit");
  else System.out.println( "x " + "is not digit");
The output will be:
5 is digit
x is not digit