Alphabet

Java programming code to check whether the character is Alphabet or not

Java programming code to check whether the character is Alphabet or not

In this post, we will discuss the concept of Java programming code to check whether the character is Alphabet or not

Here, we are going to learn how to find the given character is Alphabet or not in Java programming language

Alphabet or not

What is ASCII

In the Java programming language, all the character variables hold an ASCII value for computer usage.ASCII value is represented by integer values between 0 to 127.
The ASCII value of lowercase Alphabets are from 97 to 122 and The ASCII value of uppercase Alphabets are from 65 to 90

 

Java programming to check the character is Alphabet or not

This concept is done  using three ways

  • using if-else statements
  • Using ternary operator
  • Using ASCII value

 

Programming to check the character is Alphabet or not using if-else

The program allows the user to enter a character thereafter it will  check and display the result of the given character whether it is an alphabet or non-alphabet .using the if-else statements in Java language

Program 1

import java.util.Scanner;
class Check_Alphabet1{//class declaration
    
public static void main(String args[]){
char ch;//local variable
Scanner scan=new Scanner(System.in);
//takes input from the user
System.out.print("Enter a character: ");
//get input and it is stored ch variable
ch=scan.next().charAt(0);

if((ch>='A' && ch<='Z')||(ch>='a' && ch<='z')){
System.out.print(ch+" is an Alphabet: ");
}
else
{
System.out.print(ch+" is not an Alphabet: ");
}
}
}

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

Case 1

Enter a character: S
S is an Alphabet

 

Case 2

Enter a character: v
v is an Alphabet

 

Case 3

Enter a character: 5
5 is not an Alphabet

 

Case 4

Enter a character: %
% is not an Alphabet

 

Approach

  • In the program, the user is asked to enter a character and entered character is stored in character variable ch
  • The program evaluates whether the entered character is an Alphabet or not, using if statements
  • If the given character is an Alphabet The program displays the output “it is an Alphabet” and if the given character is not an Alphabet it will displays “it is not an Alphabet”

 

Programming to check the character is Alphabet or not using ternary operator

The program allows the user to enter a character thereafter it will  check and display the result of the given character whether it is an alphabet or non-alphabet .using the ternary operator in Java language

Program 2

import java.util.Scanner;
class Check_Alphabet2{//class declaration
    
public static void main(String args[]){
char ch;//local variable
Scanner scan=new Scanner(System.in);
//takes input from the user
System.out.print("Enter a character: ");
//get input and it is stored ch variable
ch=scan.next().charAt(0);

String result=((ch>='A' && ch<='Z')||(ch>='a' && ch<='z'))

? ch + " is an Alphabet"
: ch + " is not an Alphabet" ;
System.out.print(result);
}
}

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

Case 1

Enter a character: A
A is an Alphabet

 

Case 2

Enter a character: e
e is an Alphabet

 

Case 3

Enter a character: %
% is not an Alphabet

 

Approach

  • In the program, the user is asked to enter a character and entered character is stored in character variable ch
  • The program evaluates whether the entered character is an Alphabet or not, using ternary operator
  • If the given character is an Alphabet The program displays the output “it is an Alphabet” and if the given character is not an Alphabet it will display”it is not an Alphabet”

 

Programming to check the character is Alphabet or not using Ascii value

The program allows the user to enter a character thereafter it will  check and display the result of the given character whether it is an alphabet or non-alphabet using ASCII value in Java language

Program 3

import java.util.Scanner;
class Check_Alphabet3{//class declaration
    
public static void main(String args[]){
char ch;//local variable
Scanner scan=new Scanner(System.in);
//takes input from the user
System.out.print("Enter an character: ");
//get input and it is stored ch variable
ch=scan.next().charAt(0);


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

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

Case 1

Enter a character: A
A is an Alphabet

 

Case 2

Enter a character: s
s is an Alphabet

 

Case 3

Enter a character: 7
7 is not an Alphabet

Approach

  • In the program, the user is asked to enter a character and entered character is stored in character variable ch
  • The program evaluates whether the entered character is an Alphabet or not, using ASCII value
  • If the given character is an Alphabet The program displays the output “it is an Alphabet” and if the given character is not an Alphabet it will display”it is not an Alphabet”

The Alphabet has ASCII values between 65 to 90(capital letters) and 97 to 122 (small letters)

 

Suggested for you

The operator in Java language

Data type and variable in Java

If-else statements in Java Language

Class and main method in Java

 

Similar post

C code to check whether the character is Alphabet or not

C++ code to check whether the character is Alphabet or not

Python code to check whether the character is Alphabet or not

 

C code to check whether the Alphabet is vowel or consonant

C++ code to check whether the Alphabet is vowel or consonant

Python  code to check whether the Alphabet is vowel or consonant

Java  code to check whether the Alphabet is vowel or consonant

 

Java program to print all upper case and lower case Alphabets

C++ program to print all upper case and lower case Alphabets

C program to print all upper case and lower case Alphabets

 

Java code to print all upper case and lower case Alphabets between the given range

C++ code to print all upper case and lower case Alphabets between the given range

C code to print all upper case and lower case Alphabets between the given range

 

 

 

C++ programming code to check whether the character is Alphabet or not
Python programming code to check whether the character is Alphabet or not
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

Explanation of one dimensional array (Data structure)

Explanation of one dimensional array In this post, we will discuss the concept of "Explanation…

2 days ago

Python program to calculate the sum of odd and even numbers in a list

Python program to calculate the sum of odd and even numbers in a list In…

5 days ago

Python code to Calculate sum of odd and even in a list

Python code to Calculate sum of odd and even in a list In this tutorial,…

1 week ago

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

2 weeks ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

1 month ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

2 months ago