Home Tutorial Java Corejava Check for character is digit or not.

 
 

Check for character is digit or not.
Posted on: June 28, 2010 at 12:00 AM
This example check for the character is digit or not. It returns Boolean value.

Description:

This tutorial demonstrate the use of Character.isDigit() method which checks whether the value stored in char data-type variable is digit or not.

Code:

public class CheckDigit {
  public static void main(String[] args) {
    char charNoVar = '1';
    if (Character.isDigit(charNoVar)) {
      System.out.println("true");
    else {
      System.out.println("false");
    }
    char charVar = 'A';
    if (Character.isDigit(charVar)) {
      System.out.println("true");
    else {
      System.out.println("false");
    }
  }
}

Output:

Download this code

Related Tags for Check for character is digit or not.:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.