Alphabet

Check whether the given alphabet is uppercase or lowercase in Java

Check whether the given alphabet is upper case or lowercase

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

Check upper case or lower case

Check whether the given alphabet is upper case or lower case

Evaluate the given alphabet is upper case or lowercase

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

  1. Define a variable as char ch;
  2. The user is asked to enter a character to check upper case or lower case
  3. The entered value is stored in the variable ch;
  4. Use an if statement to check uppercase. if the test expression is true, the tested Alphabet is upper case
  5. When the if-statement is false, The control moves to else if and checks the test expression of else-if
  6. If the test expression of else-if is true,  the tested Alphabet is lower case
  7. If the test expression of else if is false, control moves to else part and executes else part statement
  8. Finally, the program displays the character whether uppercase or lowercase or not

Evaluate the given alphabet is in upper case or lowercase using Ascii value

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

  1. Define a variable as char ch;
  2. The user is asked to enter a character to check upper case or lower case
  3. The entered value is stored in the variable ch;
  4. Use an if statement to check uppercase. if the test expression is true, the tested Alphabet is upper case
  5. When the if-statement is false, The control moves to else if and checks the test expression of else-if
  6. If the test expression of else-if is true,  the tested Alphabet is lower case
  7. If the test expression of else if is false, control moves to else part and executes else part statement
  8. Finally, the program displays the character whether uppercase or lowercase or not

 

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

Program for count vowels and consonants of a string in C using ASCII value
Python Check whether the given alphabet is upper case or lowercase
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

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

1 month ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

1 month ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

9 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

9 months ago