String Java Programs

Java Program to Convert Lowercase vowel into Uppercase in String

In this tutorial, we are going to learn a python program to convert vowels (‘a’, ‘e’, ‘i’, ‘o’, ‘u’) with their respective uppercase. For any input as a string from the user, we have to convert all the vowels present in the string with their respective uppercases.

For example

Case1: If the user is given an input ‘java’
Then, the output must be ‘jAvA’.
The vowel present in the string is ‘a’ which get converted into ‘A’.

Case2: If the user is given an input ‘program’
Then, the output must be ‘prOgrAm’.
The vowels present in the string are ‘o’ and ‘a’ which get converted into ‘O’ and ‘A’.

Java Program to convert Lowercase Vowel to Uppercase in String

import java.util.*;

public class Main {
	public static void main(String[] args) {
		ArrayList<Character> arr = new ArrayList<Character>(
				Arrays.asList('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'));
		System.out.println("Java program to convert Vowel into 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)) && arr.contains(str.charAt(i))) {
				strBuffer.setCharAt(i, Character.toUpperCase(str.charAt(i)));
			}
		}
		System.out.println("After Conversion Vowel into uppercase");
		System.out.println(strBuffer);
	}
}

Output

Java program to convert Vowel into uppercase
Please enter a String
java
After Conversion Vowel into uppercase
jAvA

Explanation

In this case, the input string ‘java’ contains one vowels ‘a’ which gets converted into ‘A’ and replaced with the same. After replacement output will be jAvA.

About the Author: Elavarasan PK

Technical Specialist, Intersoft Data Labs