char c = '3'; if(Character.isLetterOrDigit(c)) { System.out.println(c + " is a letter or a digit"); } else { System.out.println(c + " is not a letter or a digit"); }
3 is a letter or a digit
char c = '%'; if(Character.isLetterOrDigit(c)) { System.out.println(c + " is a letter or a digit"); } else { System.out.println(c + " is not a letter or a digit"); }
% is not a letter or a digitIn this example, the isLetterOrDigit() method is used to determine whether the character '%' is a letter or a digit. Since it is neither a letter nor a digit, the method returns false. The isLetterOrDigit() method is part of the java.lang package library.