Java Program to Check Whether a Character is Alphabet or Not

This tutorial provides Java Program to Check Whether a Character is Alphabet or Not.

import java.util.Scanner;

public class AlphabetFinder
{
    public static void main(String args[])
    {
        char character;
        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter a Character : ");
        character = scanner.next().charAt(0);

        if((character>='a' && character<='z') || (character>='A' && character<='Z')){
            System.out.print(character + " is an alphabet.");
        }else{
            System.out.print(character + " is not an alphabet.");
        }
    }
}

Output:

Enter a Character : d
d is an alphabet.

The ASCII value of lowercase alphabets range from 97 to 122. And, the ASCII value of uppercase alphabets range from 65 to 90.

That’s why, we compared variable character between ‘a’ (97) to ‘z’ (122) for lowercase character and between ‘A’ (65) to ‘Z’ (90) for uppercase character.

That’s all about Java Program to Check Whether a Character is Alphabet or Not.

[social_share share_on="facebook,twitter,linkedin,whatsapp"][post_navigator in_same_term="true"]

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.