Write a program to check whether a character is uppercase or lowercase alphabet


The program is a Java program that takes a single character input from the user and checks whether it is a lowercase or an uppercase alphabet.

  • The program starts by importing the java.util.Scanner package which allows user input to be taken from the console.
  • In the main method, the program prompts the user to enter a single character using the System.out.print method and reads the input using the Scanner object's next() method.
  • The program then checks whether the entered character is a lowercase alphabet or not using an if statement. The condition of the if statement checks if the entered character is between 'a' and 'z' using the logical AND (&&) operator. If the condition is true, the program prints "This is a Lowercase Alphabet" using the System.out.println() method.
  • If the entered character is not a lowercase alphabet, the program assumes that it is an uppercase alphabet and prints "This is an Uppercase Alphabet" using the System.out.println() method.
  • Finally, the program exits the main method, and the program execution ends.

Source Code

import java.util.Scanner;
class Upper_Lower
{
	public static void main(String[] args)
	{
		Scanner input = new Scanner(System.in);
		System.out.print("Enter the Character :");
		char ch = input.next().charAt(0);			
		if(ch>='a' && ch<='z')
		{
			System.out.println("This is a Lowercase Alphabet");
		}
		else
		{
			System.out.println("This is a Uppercase Alphabet");
		}
	}
}

Output

Enter the Character :t
This is a Lowercase Alphabet

Enter the Character :D
This is a Uppercase Alphabet

Example Programs