C C++ Java Data Structure Python JavaScript CSS Ajax PL/SQL PHP Puzzles C programs C++ programs Java programs

Home » Java programs » Java basic programs

Java program to check whether a given character is alphabet or not

In this java program, we will learn how to check whether a given character in an alphabet or not? Here, we are reading a character from the user and validating it is alphabet or not.
Submitted by IncludeHelp, on December 05, 2017

Given a character and we have to check whether it is an alphabet or not?

Example 1:

Enter a character: A
A is an alphabet 

Example 2:

Enter a character: @
@ is not an alphabet 

Program to check given character is an alphabet or not in java

import java.util.Scanner;

public class AlphabetOrNot
    public static void main(String args[])
    	//create and initialize object.
        char ch;
        Scanner scan = new Scanner(System.in);
        //Input character
        System.out.print("Enter a Character : ");
        ch = scan.next().charAt(0);
        //condition for checking characters.
        if((ch>='a' && ch<='z') || (ch>='A' && ch<='Z'))
            System.out.print(ch + " is an Alphabet");
            System.out.print(ch + " is not an Alphabet");


First run:
Enter a Character : A
A is an Alphabet

Second run:
Enter a Character : @
@ is not an Alphabet

Liked this article? Do share with your friends :)

Are you a blogger? Join our Blogging forum.