Home » Java programming language

Java Character class isDigit() method with example

Character class isDigit() method: Here, we are going to learn about the isDigit() method of Character class with its syntax and example.
Submitted by Preeti Jain, on October 26, 2019

Character class isDigit() method

  • isDigit() method is available in java.lang package.
  • isDigit() method is used to check whether the given char value is a digit or not.
  • isDigit() method does not throw an exception at the time of checking the given char value is a digit or not.

Syntax:

    public boolean isDigit(Char c);

Parameter(s):

  • Char c – represents the char value to be checked.

Return value:

The return type of this method is boolean, it returns a boolean value based on the following cases,

  • It returns true, if the given char value is digit.
  • It returns false, if the given char value is not digit.

Example:

// Java program to demonstrate the example 
// of boolean isDigit (Char c) method of Character class

public class IsDigitOfCharacterClass {
    public static void main(String[] args) {

        // It returns false because the passing 
        // character is not digit   
        boolean result1 = Character.isDigit('a');

        // It returns true because the passing 
        // character is a digit   
        boolean result2 = Character.isDigit('7');

        // Display values of result1 , result2
        System.out.println("Character.isDigit('a'): " + result1);
        System.out.println("Character.isDigit('7'): " + result2);
    }
}

Output

Character.isDigit('a'): false
Character.isDigit('7'): true





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.