Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c
C program to check whether a character is an Alphabets or Not

Java program to check whether a character is an Alphabets or Not

Posted on February 25, 2022February 27, 2022

Table of Contents

  • Java program to check whether a character is an Alphabets or Not
    • Code to check character is Alphabet or Not
      • Code to check the character is Alphabet or Not using If else
      • Code to check the character is Alphabet or Not using Ascii
      • Code to check the character is Alphabet or Not using ternary operator
      • Code to check the character is Alphabet or Not using isAlphabetic()

Java program to check whether a character is an Alphabets or Not

In this article, we will discuss the concept of Java program to check whether a character is an Alphabets or Not

In this post, we are going to learn how to write a program to  check whether given character is English alphabet or not  using various ways in Java language

Code to check character is Alphabet or Not

Code to check the character is Alphabet or Not using If else

In this code, we are going to learn how to check  the given character is  English alphabet or not using if-else in Java language

Program 1

import java.util.Scanner;
class Check_Eng_Alphabet1{//class declaration
  
public static void main(String args[]){//main method
char ch;//declare a character variable
Scanner scan=new Scanner(System.in);
//take input from the user for alphabets
System.out.print("Enter a character for check Alphabets: ");
//get input and store in ch variable
ch=scan.next().charAt(0);
//read the character
if((ch>='A' && ch<='Z')||(ch>='a' && ch<='z')){
  //check the given character is Alphabet or not
System.out.print(ch+" is an Alphabet: ");
}
else
{
System.out.print(ch+" is not an Alphabet: ");
}
}
}

When the above code is executed, it produces the following result

Case 1

Enter a character for check Alphabets:
r
r is an Alphabets

Case 2

Enter a character for check Alphabets:
5
5 is not an Alphabets

 

Code to check the character is Alphabet or Not using Ascii

In this code, we are going to learn how to check  the given character is  English alphabet or not, using Ascii value in Java language

Program 2

import java.util.Scanner;
class Check_Eng_Alphabet3{//class declaration
  
public static void main(String args[]){
char ch;//declare character variable
Scanner scan=new Scanner(System.in);
//take input from the user
System.out.print("Enter a character for check Alphabet: ");
//get input and store in ch variable
ch=scan.next().charAt(0);
//read the input from the user

if((ch>=97 && ch<=122)||(ch>=65 && ch<=90)){
System.out.print(ch+" is an Alphabet: ");
}//using Ascii value to check Alphabets
else
{
System.out.print(ch+" is not an Alphabet: ");
}
}
}

When the above code is executed, it produces the following result

Case 1

Enter a character for check Alphabets
A
A is an Alphabets

Case 2

Enter a character for check Alphabets:
#
# is not an Alphabets

 

 

Code to check the character is Alphabet or Not using ternary operator

In this code, we are going to learn how to check  the given character is  English alphabet or not, using ternary operator in Java language

Program 3

import java.util.Scanner;
class Check_Eng_Alphabet2{//class declaration
  
public static void main(String args[]){//java main method
char ch;//declare a character variable
Scanner scan=new Scanner(System.in);
//take input from the user
System.out.print("Enter a character for check Alphabet: ");
//get input and stord in ch variable
ch=scan.next().charAt(0);
//read the character
String result=((ch>='A' && ch<='Z')||(ch>='a' && ch<='z'))
//check the given character is Alphabet or not using ternary
? ch + " is an Alphabet"
: ch + " is not an Alphabet" ;
System.out.print(result);
}
}

 

When the above code is executed, it produces the following result

Case 1

Enter a character for check Alphabets:
Z
Z is an Alphabets

Case 2

Enter a character for check Alphabets:
*
* is not an Alphabets

 

 

Code to check the character is Alphabet or Not using isAlphabetic()

In this code, we are going to learn how to check  the given character is  English alphabet or not, using isAlphabetic() method in Java language

Program 4

import java.util.Scanner;
class Check_Eng_Alphabet4{//class declaration
  
public static void main(String args[]){
char ch;//declare character variable
Scanner scan=new Scanner(System.in);
//take input from the user
System.out.print("Please Enter a character for check Alphabet: ");
//get input and store in ch variable
ch=scan.next().charAt(0);
//read the input from the user

if(Character.isAlphabetic(ch)){
System.out.print(ch+" is an Alphabet: ");
}//check the given character is Alphabet or not using isAlphabetic() function
else
{
System.out.print(ch+" is not an Alphabet: ");
}
}
}

When the above code is executed, it produces the following result

Case 1

Please Enter a character for check Alphabets:
W
W is an Alphabets

Case 2

Please Enter a character for check Alphabets:
$
$ is not an Alphabets

 

Suggested post

if statement in Java language

Nested if statements in Java language

Method in Java language

 

For loop in Java language

While loop in Java language

Do-while loop in Java language

Operator in Java language

Variable in Java language

Data type in Java language

class and main method in Java

 

Similar post

Java program to print all alphabets in given range

C program to print all alphabets in given range

C++ program to print all alphabets in given range

 

Java program to print all alphabets using loops

C program to print all alphabets using loops

C++ program to print all alphabets using loops

 

Java program to check whether a character is Alphabet or Not

C++ program to check whether a character is Alphabet or Not

C program to check whether a character is Alphabet or Not

Python program to check whether a character is Alphabet or Not

 

Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes