Table of Contents
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
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
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
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
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
Nested if statements in Java language
Do-while loop in Java language
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
Subtract two numbers using method overriding Program 1
PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…
Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…
Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…
Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…
How to write a program to convert Fahrenheit into Celsius In this article, we will…
This website uses cookies.