English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Java에서 입력 값이 숫자인지 확인

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 the complete example to check uppercase letters in Java.

Example

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!