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:

Input:
Enter a character: A
Output:
A is an alphabet 

Example 2:

Input:
Enter a character: @
Output:
@ 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");
        }
        else
        {
            System.out.print(ch + " is not an Alphabet");
        }
    }
}

Output

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

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

Java Basic Programs »



Related Programs

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT


Top MCQs

Comments and Discussions!




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.