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:
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)
Australia
UK
UAE
Singapore
Canada
New
Zealand
Malaysia
USA
India
South
Africa
Ireland
Saudi
Arab
Qatar
Kuwait
Hongkong
Copyright 2016-2023 www.programmingshark.com - All Rights Reserved.
Disclaimer : Any type of help and guidance service given by us is just for reference purpose. We never ask any of our clients to submit our solution guide as it is, anywhere.