Java program to Convert Lowercase Character to Uppercase Character

In this tutorial, we are going to java a java program to convert lowercase characters (alphabet) into uppercase characters (alphabet).

For any input string, any lowercase character used in input string will be replaced with uppercase character of same alphabet as lowercase character.

For example

Case1: if user inputs ‘Quescol’

         The output should be ‘QUESCOL’

Case2: if user inputs ‘jaVa’

         The output should be ‘JAVA’

Java Program to Convert Lowercase Character to Uppercase Character

import java.util.*;
public class Main
{
    public static void main (String[]args)
    {
        System.out.println("Java program to convert lowecase to uppercase");
        Scanner sc = new Scanner (System.in);
        System.out.println ("Please enter a String");
        String str = sc.nextLine();
        StringBuffer strBuffer = new StringBuffer(str); 
        for(int i = 0; i < str.length(); i++){
            if(Character.isLowerCase(str.charAt(i))) {  
                strBuffer.setCharAt(i, Character.toUpperCase(str.charAt(i)));    
            }
        }
        System.out.println("After Conversion lowecase to uppercase");
        System.out.println(strBuffer);
    }
}

Output

Java program to convert lowecase to uppercase
Please enter a String
Quescol
After Conversion lowecase to uppercase
QUESCOL

Explanation

For the input string ‘Quescol’, all the lowercase letters i.e. ‘uescol’ is converted into respective uppercase i.e. ‘UESCOL’ While iterating through the string, the letters ‘u’, ‘e’, ‘s’, ‘c’, ‘o’, and ‘l’  return ‘True” as an output when is checked with ‘isLowerCase()’ function, then they are converted into respective uppercase letters using ‘isUpperCase()’ function and replaced simultaneously.