Knowee
Questions
Features
Study Tools

Write a method that takes in a String and returns a newstring that replaces every vowel with two occurrences ofthat vowel.For example:doubleVowel("hello")would returnheelloo

Question

Write a method that takes in a String and returns a newstring that replaces every vowel with two occurrences ofthat vowel.For example:doubleVowel("hello")would returnheelloo

🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is a simple method in Java that accomplishes this:

public class Main {
    public static void main(String[] args) {
        System.out.println(doubleVowel("hello"));
    }

    public static String doubleVowel(String input) {
        String vowels = "aeiouAEIOU";
        StringBuilder newString = new StringBuilder();

        for (int i = 0; i < input.length(); i++) {
            char c = input.charAt(i);
            if (vowels.contains(String.valueOf(c))) {
                newString.append(c).append(c);
            } else {
                newString.append(c);
            }
        }

        return newString.toString();
    }
}

This method works by iterating over each character in the input string. If the character is a vowel (i.e., it is contained in the string "aeiouAEIOU"), it appends the character twice to the new string. If the character is not a vowel, it simply appends the character to the new string. The method then returns the new string.

This problem has been solved

Similar Questions

Write a function that takes a string as input and returns a new string with all the vowels removed.

Write a program that will take one string as input. The program will then remove vowels a, e, i, o, u (in lower or upper case) from the string. If there are two or more than two vowels that occur together then the program shall ignore all of those vowels.Sample input Cat Sample output CtSample input HeelSample output Heel

Define a class to accept a string and convert it into uppercase. Count and display thenumber of vowels in it.

Read any string and display the vowels

Problem Statement You are given a function, char* VowelConsonantSequence(char* str); The function takes a string 'str' as input. All consecutive consonants are replaced by a single letter 'C' and all consecutive vowels are replaced by a single letter 'V', such that output string does not have two or more consecutive 'C' or 'V'. Implement the function to generate this string of alternate 'C' and 'V' and return the same. Note: str will contain only lower case English alphabets. The vowels in the English alphabets are 'a', 'e', 'i', 'o' and 'u'. All the other alphabets are consonants. Output string should have only upper-case letters 'C' and 'V'. Example: Input: whereabouts Output: CVCVCVC Explanation: Here, the sequence in the input string is consonant-consonant-vowel-consonant-vowel-vowel-consonant-vowel-vowel-consonant-consonant. Putting together consecutive consonants and vowels gives us CVCVCVC. Note that the sequence has been preserved along with the constraint that no two "V"s or "C"s appear together. Sample input yoghurt Sample Output CVCVC Instructions : This is a template based question, DO NOT write the "main" function. Your code is judged by an automated system, do not write any additional welcome/greeting messages. "Save and Test" only checks for basic test cases, more rigorous cases will be used to judge your code while scoring. Additional score will be given for writing optimized code both in terms of memory and execution time.

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.