

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to Check Whether a Character is Alphabet or Not
In this article, we will understand how to check whether a character is alphabet or not. This is accomplished by checking if the given character lies in between the alphabets a to z or A to Z.
Below is a demonstration of the same −
Input
Suppose our input is −
Enter a character: H
Output
The desired output would be −
The character H is an alphabet
Algorithm
Step 1 - START Step 2 - Declare a character value namely my_input Step 3 - Read the required values from the user/ define the values Step 4 - Using an if-else condition, check if the input value lies in between ‘a’ and ‘z’ or ‘A’ and ‘Z’ using comparison operators ‘>=’ and ‘<=’ . If true, its an alphabet, else its not an alphabet/ Step 5 - Display the result Step 6 - Stop
Example 1
Here, the input is being entered by the user based on a prompt. You can try this example live in our coding ground tool .
import java.util.Scanner; public class Alphabet { public static void main(String[] args) { char my_input; System.out.println("Required packages have been imported"); Scanner my_scanner = new Scanner(System.in); System.out.println("A reader object has been defined "); System.out.print("Enter the character : "); my_input = my_scanner.next().charAt(0); if( (my_input >= 'a' && my_input <= 'z') || (my_input >= 'A' && my_input <= 'Z')) System.out.println("The character " +my_input + " is an alphabet"); else System.out.println("The character " +my_input + " is not an alphabet"); } }
Output
Required packages have been imported A reader object has been defined Enter the character : H The character H is an alphabet
Example 2
Here, the integer has been previously defined, and its value is accessed and displayed on the console.
public class Alphabet { public static void main(String[] args) { char my_input; my_input = 'H'; System.out.println("The Alphabet is defined as " +my_input); if( (my_input >= 'a' && my_input <= 'z') || (my_input >= 'A' && my_input <= 'Z')) System.out.println("The character " +my_input + " is an alphabet."); else System.out.println("The character " +my_input + " is not an alphabet."); } }
Output
The Alphabet is defined as H The character H is an alphabet.
- Related Questions & Answers
- Java program to find whether the given character is an alphabet or not
- Check whether a character is Uppercase or not in Java
- Check whether a character is Lowercase or not in Java
- Java Program to Check Whether an Alphabet is Vowel or Consonant
- Java Program to Check Whether a Number is Prime or Not
- Java program to check whether a given string is Heterogram or not
- Java Program to check whether a file exists or not
- C++ Program to Check Whether a character is Vowel or Consonant
- Check input character is alphabet, digit or special character in C
- C# program to check whether a list is empty or not
- Python program to check whether a list is empty or not?
- C++ Program to Check Whether a Number is Prime or Not
- C++ Program to Check Whether a Number is Palindrome or Not
- C Program to Check Whether a Number is Prime or not?
- Check whether a Stack is empty or not in Java
Advertisements