In this article, we will discuss the concept of the Check whether the given alphabet is upper case or lowercase in Java
In this post, we are going to learn how to check the given alphabet is upper case or lowercase in Java programming language
The program allows to enter a character, thereafter it checks and displays whether the given character an upper case or lower case
Program 1
import java.util.Scanner; public class CheckUpperLower{ public static void main(String args[]){ char ch;//variable declaration Scanner scan=new Scanner(System.in); //create a scanner object for input System.out.println("Enter the character "); ch=scan.next().charAt(0);;// store the input from the user if(ch>='A' && ch<='Z'){//if it is true ,display upper case System.out.println(ch+" is an upper case letter "); } else if(ch>='a' && ch<='z'){//if it is true ,display lower case System.out.println(ch+" is a lower case letter "); } else{ System.out.println(ch+" is not a Alphabets "); } } }
When the above code is executed, it produces the following result
Case 1
Enter the Character A A is an upper case letter
Case 2
Enter the Character a a is a lower case letter
Case 3
Enter the Character $ $ is not an Alphabets
Approach
The program allows to enter the character, thereafter it checks and displays whether the given character is an upper case or lower case using ASCII value
Program 2
import java.util.Scanner; public class CheckUpperLower1{ public static void main(String args[]){ char ch;//variable declaration Scanner scan=new Scanner(System.in); //create a scanner object for input System.out.println("Enter the character for find case "); ch=scan.next().charAt(0);;// store the input from the user if(ch>=65 && ch<=90){ System.out.println(ch+" is an upper case letter "); } else if(ch>=97 && ch<=122){ System.out.println(ch+" is a lower case letter "); } else{ System.out.println(ch+" is not an Alphabets "); } } }
When the above code is executed, it produces the following result
Case 1
Enter the Character M M is an upper case letter
Case 2
Enter the Character d d is a lower case letter
Case 3
Enter the Character % % is not an Alphabets
Approach
Suggested for you
Datatype and variable in Java language
The operator in Java language
If statements in Java language
Similar post
Check whether the given alphabet is in upper case or lowercase in Python
Check whether the given alphabet is in upper case or lowercase in C++
Check whether the given alphabet is in upper case or lowercase in C
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…
Java program to check odd or even using recursion In this tutorial, we discuss a…