Alphabets

Program to check whether a character is upper or lower case or not in Java

Program to check whether a character is upper, lower case or not in Java

In this article, we will discuss the concept of Program to check whether a character is upper, lower case or not in Java

In this post, we are going to learn how to write a program to  check whether given character is Upper case or lower case or not using if else in Java language

Code to check given character is Upper or Lower or not

Code to check given character Upper or Lower or not, using if statements

In this code, we are going to learn how to check  the given  character is Upper case or lower case or not using if else statements in Java language

Program 1

import java.util.Scanner;
public class CheckUpperLowerNot{
public static void main(String args[]){
  char ch;//char 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);;// reading the input from the user

if(ch>='A' && ch<='Z'){
  System.out.println(ch+" is an upper case letter ");
}//check upper case letter
else if(ch>='a' && ch<='z'){
  System.out.println(ch+" is a lower case letter ");
}//check lower case letter
else{//disply non-alphabet character
  System.out.println(ch+" is not an Alphabet ");
}
}
}

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
h
h is a lower case letter

Case 3

Enter the character
7
7 is not an Alphabet

 

Code to check given character is Upper or Lower or not , using Ascii

In this code, we are going to learn how to check  the given  character is Upper case or lower case using if else statements in Java language

Program 2

import java.util.Scanner;
public class CheckUpperLowerNot1{
public static void main(String args[]){
  char ch;//char variable declaration

 Scanner scan=new Scanner(System.in); 
  //create a scanner object for user input
  
System.out.println("Enter the character for find case ");
ch=scan.next().charAt(0);;// reading the input from the user

if(ch>=65 && ch<=90){
  System.out.println(ch+" is an upper case letter ");
}//check upper case Alphabet
else if(ch>=97 && ch<=122){
  System.out.println(ch+" is a lower case letter ");
}//check lower case Alphabet
else{
  System.out.println(ch+" is not a Alphabets ");
}//display if the character 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
g
g is a lower case letter

Case 3

Enter the character
&
& is not an Alphabets

 

Code to check given character is Upper or Lower , using Character class

In this code, we are going to learn how to check  the given  character is Upper case or lower case or not using Character class in Java language

Program 3

import java.util.Scanner;
public class CheckUpperLowerNotChar{
public static void main(String args[]){
  char ch;//char variable declaration

 Scanner scan=new Scanner(System.in); 
  //create a scanner object for user input
  
System.out.println("Enter the character for find case ");
ch=scan.next().charAt(0);;// reading the input from the user

if(Character.isUpperCase(ch)){
  System.out.println(ch+" is an upper case letter ");
}//check upper case Alphabet
else if(Character.isLowerCase(ch)){
  System.out.println(ch+" is a lower case letter ");
}//check lower case Alphabet
else{
  System.out.println(ch+" is not a Alphabets ");
}//display if the character is not an alphabets
}
}

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

Case 1

Enter the character to find case
E
E is an upper case letter

Case 2

Enter the character to find case
c
c is an lower case letter

Case 3

Enter the character to find case
$
$ 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

Multiply two numbers in Java using scanner| 5 different ways

Multiply two numbers in Java using scanner| 5 different ways In this article, we will…

3 months ago

5 different ways to Divide two numbers in Java using scanner

5 Different ways to Divide two numbers in Java using scanner In this article, we…

3 months ago

Learn 8 Ways to Subtract Two Numbers Using Methods in Java

Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…

4 months ago

10 ways to subtract two numbers in Java

10 ways to subtract two numbers in Java In this article, we will discuss the…

4 months ago

Java Code Examples – Multiply Two Numbers in 5 Easy Ways

Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…

4 months ago

How to Divide two numbers in Java| 5 different ways

How to Divide two numbers in Java| 5 different ways In this article, we will…

4 months ago

This website uses cookies.