Skip to main content

ProwessApps

Learn · Practice · Excel

Java Program to convert lower case to upper case

Java Code Example — String Programs

ADVERTISEMENT

Java Program to convert lower case to upper case

Objective

Write a Java program to convert a lowercase string to uppercase.

Algorithm / Approach

  1. Accept a string from the user and store it in s1.
  2. Call the built-in toUpperCase() method on s1.
  3. Store the result in s2.
  4. Print s2.
Test.java
import java.util.Scanner;
class Test {
 public static void main(String[] a)
 {
  Scanner s=new Scanner(System.in);
  System.out.print("Enter String: ");
  String s1 = s.nextLine();
  String s2 = s1.toUpperCase();
  System.out.print("Upper Case = "+s2);
 }
}

Expected Output

Enter String: java Prowess
Upper Case = JAVA PROWESS

Explanation of the Program

  • Java provides highly optimized built-in methods for case conversion: toUpperCase() and toLowerCase().
  • These methods automatically handle characters correctly and ignore numbers or special punctuation marks without throwing errors.
  • Because strings are immutable, the original s1 string remains untouched, and a new uppercase string is returned.

Complexity

Time Complexity O(n)
Space Complexity O(n)
ADVERTISEMENT