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 LowerCase Vowel into uppercase in String=== \n");
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 LowerCase Vowel into uppercase in String===
Please enter a String:
quescol
After Conversion Vowel into uppercase
qUEscOl
Explanation
In this case, the input string ‘quescol’ contains three vowels ‘u’, ‘e’,’o’ which gets converted into ‘U’, ‘E’, ‘O’ and replaced with the same. After replacement output will be qUEscOl.