Menu
Topics Index
...
`

Character - Java Example Program


Character
class CharacterTest
{
    public static void main(String arg[])
    {
        System.out.println("Checks for letter : " + Character.isLetter('M'));
        System.out.println("Checks for digit : " + Character.isDigit('5'));
        System.out.println("Checks for white space : " + Character.isWhitespace(' '));
        System.out.println("Checks for uppercase : " + Character.isUpperCase('C'));
        System.out.println("Checks for lowercase : " + Character.isLowerCase('c'));
        System.out.println("Converts to uppercase : " + Character.toUpperCase('m'));
        System.out.println("Converts to lowercase : " + Character.toLowerCase('Z'));
        System.out.println("Converts to string : " + Character.toString('w'));    
    }
}
OUTPUT

Checks for letter : true
Checks for digit : true
Checks for white space : true
Checks for uppercase : true
Checks for lowercase : true
Converts to uppercase : M
Converts to lowercase : z
Converts to string : w

DESCRIPTION

In this program, all the character methods are used.

THINGS TO TRY
  • Give '8' in isLetter method and see the output which returns false.
  • Give 'k' in isDigit method and see the output which returns false.
  • Give '\t', '\n' in isWhitespace method and see the output which returns true as newline and tab contains space.
  • Take a character and replace in isUppercase, isLowercase, toUppercase, toLowercase and toString methods.

© meritcampus 2019

All Rights Reserved.

Open In App