How to convert vowels into upper case character in a given string?

Given string str, the task is to convert all vowels present in the given string to uppercase characters in the given string.

Examples:

Input: str = “GeeksforGeeks”
Output: GEEksfOrGEEks
Explanation:
Vowels present in the given string are: {‘e’, ‘o’}
Replace ‘e’ to ‘E’ and ‘o’ to ‘O’.
Therefore, the required output is GEEksfOrGEEks.

Input: str = “eutopia”
Output: EUtOpIA

Approach:

The idea is to iterate the characters in a given string and check if the current character is a lowercase character and a vowel character. If true, the characters are converted to uppercase. Please follow the steps below to solve the problem:

  • Loop through the given string and check if str [i] is a lowercase vowel.
  • If it is found to be true, replace str [i] with (str [i]-'a' +'A').
  • Finally, after completing the chain crossover, print the final chain.

Below is the implementation of the approach:

// Java program to implement
// the above approach
import java.util.*;
class GFG{

// Function to convert vowels
// into uppercase
static void conVowUpp(char[] str)
{
// Stores the length
// of str
int N = str.length;

for (int i = 0; i < N; i++)
{
	if (str[i] == 'a' || str[i] == 'e' ||
		str[i] == 'i' || str[i] == 'o' ||
		str[i] == 'u')
	{
	char c = Character.toUpperCase(str[i]);
	str[i] = c;
	}
}
for(char c : str)
	System.out.print(c);
}

// Driver Code
public static void main(String[] args)
{
String str = "eutopia";
conVowUpp(str.toCharArray());
}
}

// This code is contributed by 29AjayKumar

Output: 

EUtOpIA

Time Complexity: O(N)
Auxiliary Space: O(1)

Submit Your Programming Assignment Details