English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
To check if the input value is a digit in Java, use the Character.isDigit() method.
We have a character to check.
char val = '5';
Now let's use the Character.isDigit() method.
if (Character.isDigit(val)) { System.out.println("Character is a digit!"); } else { System.out.println("Character is not a digit!"); }
Now let's see a complete example to check uppercase letters in Java.
public class Demo { public static void main(String []args) { System.out.println("Checking for digit..."); char val = '5'; System.out.println("Value: "+val); if (Character.isDigit(val)) { System.out.println("Character is a digit!"); }else { System.out.println("Character is not a digit!"); } } }
Output Result
Checking for digit... Value: 5 Character is a digit!