
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
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 Articles
- C++ Program to Check Whether a Character is Alphabet or Not
- Haskell Program to Check Whether a Character is Alphabet or Not
- Java program to find whether the given character is an alphabet or not
- How to check whether a character is in the Alphabet or not in Golang?
- Java Program to Check Whether an Alphabet is Vowel or Consonant
- Check whether a character is Lowercase or not in Java
- Check whether a character is Uppercase or not in Java
- Java Program to Check Whether a Number is Prime or Not
- Haskell Program to Check Whether an Alphabet is Vowel or Consonant
- Java Program to check whether a file exists or not
- Java program to check whether a given string is Heterogram 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 Number is Prime or Not
- C++ Program to Check Whether a Number is Palindrome or Not

Advertisements