Friday, December 22, 2017

JAVA - How check if character is number

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" );
Output:
5 is digit
x is not digit

No comments:

Post a Comment