Share on Google+Share on Google+

Check for character is digit or not.

Advertisement
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

Advertisements

Posted on: June 28, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.