Java ProgramsControl FlowCheck Uppercase or Lowercase

Check Uppercase or Lowercase in Java

beginner·  Control Flow  ·  Conditional Statements

Problem

Uppercase and lowercase letters occupy two separate, non-overlapping ranges of character codes — 'A' to 'Z' for uppercase and 'a' to 'z' for lowercase.

Given a single alphabet character, determine whether it is uppercase or lowercase.

Input
'G'
Output
'G' is uppercase

Java Program

Java
public class CaseCheck { public static void main(String[] args) { char ch = 'G'; if (ch >= 'A' && ch <= 'Z') { // assumes ch is already a letter System.out.println("'" + ch + "' is uppercase"); } else { System.out.println("'" + ch + "' is lowercase"); } } }

Output

'G' is uppercase

Core Logic

Checking which of the two separate letter-case ranges a character falls into settles the question directly.

How It Works
  1. 1(ch >= 'A' && ch <= 'Z') checks whether the character falls in the uppercase range.
  2. 2If that check fails, the character is assumed lowercase — this example only handles letters, not digits or symbols.
  3. 3The matching branch prints the appropriate message.
For ch = 'G', it falls between 'A' and 'Z', so the uppercase branch runs.
💡

Key Point: This assumes the input is already a letter — pair it with an alphabet check first if the input might not be.

Key Concepts

character range checkif / else

Approach 2: Using Character.isUpperCase() and isLowerCase()

Java
public class CaseCheckBuiltIn { public static void main(String[] args) { char ch = 'G'; if (Character.isUpperCase(ch)) { System.out.println("'" + ch + "' is uppercase"); } else { System.out.println("'" + ch + "' is lowercase"); } } }

Output

'G' is uppercase

Core Logic

Java's Character class has dedicated methods for exactly this, sparing a manual range check for either case.

How It Works
  1. 1Character.isUpperCase(ch) reports whether the character is an uppercase letter.
  2. 2Character.isLowerCase(ch) reports the same for lowercase, used in the fallback branch.
Character.isUpperCase('G') returns true, so the uppercase message is printed.
💡

Key Point: These built-in methods also correctly classify uppercase and lowercase letters outside the basic ASCII alphabet, which the manual range check does not.

Key Concepts

Character.isUpperCase()Character.isLowerCase()

Related Programs