InterviewSolution
Saved Bookmarks
| 1. |
Check if a character is letter or number in Java |
|
Answer» The method isLetterOrDigit() can be used to check if a character is a letter or a number in Java. If the character is a letter or a number then the method returns true, OTHERWISE it returns false. A program that demonstrates this is given as follows: public class MAINCLASS { public STATIC void main(String[] args) { char CHARACTER1 = 'A'; char character2 = '*'; if (Character.isLetterOrDigit(character1)) { System.out.println(character1 + " is a character or DIGIT"); } else { System.out.println(character1 + " is not a character or digit"); } if (Character.isLetterOrDigit(character2)) { System.out.println(character2 + " is a character or digit"); } else { System.out.println(character2 + " is not a character or digit"); } } }The output of the above program is as follows: A is a character or digit * is not a character or digit |
|