String Java Programs

Java program to Convert Lowercase Character to Uppercase Character

In this tutorial, we are going to see 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 ‘Hitechpoints’
The output should be ‘HITECHPOINTS’

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
Hitechpoints
After Conversion lowecase to uppercase
HITECHPOINTS

Explanation

For the input string ‘Hitechpoints’, all the lowercase letters i.e. ‘itechpoints’ is converted into respective uppercase i.e. ‘ITECHPOINTS’ While iterating through the string, the letters ‘i’, ‘t’, ‘e’, ‘c’, ‘h’, ‘p’, ‘o’, ‘i’, ‘n’, ‘t’, and ‘s’  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.

About the Author: Elavarasan PK

Technical Specialist, Intersoft Data Labs