Alphabets

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

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

 

Karmehavannan

Recent Posts

Subtract two numbers using method overriding

Subtract two numbers using method overriding   Program 1

3 months ago

PHP Star triangle Pattern program

PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…

3 months ago

Using function or method to Write temperature conversion : Fahrenheit into Celsius

Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…

1 year ago

Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user

Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…

1 year ago

Write temperature conversion program: Fahrenheit into Celsius

Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…

1 year ago

How to write a program to convert Fahrenheit into Celsius

How to write a program to convert Fahrenheit into Celsius In this article, we will…

1 year ago

This website uses cookies.