Question

Write the method: public static String doubleVowels(String x). This method takes a String x and returns...

Write the method: public static String doubleVowels(String x). This method takes a String x and returns a new String y which is identical to x except wherever there is a vowel in x, there will be two of that same vowel in the returned String y. The original String x will contain only lower case letters.


For example, doubleVowels("easy") should return the String "eeaasy".
Another example: doubleVowels("abootstrap") should return the String "aabooootstraap".
Another example: doubleVowels("gggrrrhh") should return the String "gggrrrhh".


public static String doubleValue(String x) {

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The solution for the above question is given below with the screenshot of output.
----------------------------------------------------------------------------------

I have kept the logic simple and output as per the question.

If there is anything else do let me know in comments

----------------------------------------------------------------------------------

-------------------------- CODE TO COPY ------------------------------------------

import java.util.Scanner;

class Main {

  // double vowels in string
  public static String doubleVowels(String x) {

    int i;
    int size = x.length(); // find length of string
    String y = "\0";

    // loop for find vowels in string
    for( i =0; i < size; i++) {
      if(x.charAt(i) == 'a' || x.charAt(i) == 'e' || x.charAt(i) == 'i' || x.charAt(i) == 'o' || x.charAt(i) == 'u') {  // if string contain vowels
        y = y + x.charAt(i) + x.charAt(i);
      }
      else { // string contain consonents
        y = y +  x.charAt(i);
      }
    }
    
    return y;
  }

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    
    // input string
    System.out.print("Enter String : ");

    String y = sc.nextLine();

    // change string into lower case
    y = y.toLowerCase();

    y =  doubleVowels(y);

   System.out.println("Final String : " +y);

  }
}

Output : -----------------------------------------------------------------

Add a comment
Know the answer?
Add Answer to:
Write the method: public static String doubleVowels(String x). This method takes a String x and returns...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a public static method named getMaxOf2Ints that takes in 2 int arguments and returns the...

    Write a public static method named getMaxOf2Ints that takes in 2 int arguments and returns the Maximum of the 2 values Write a public static method named getMinOf2Ints that takes in 2 int arguments and returns the Minimum of the 2 values Write apublic static method named getMaxOf3Ints that takes in 3 int arguments and returns the Maximum of the 3 values Write a public static method named getMedianOf3Ints that takes in 3 int arguments and returns the Median Value...

  • project-8a Write a function named count_letters that takes as a parameter a string and returns a...

    project-8a Write a function named count_letters that takes as a parameter a string and returns a dictionary that tabulates how many of each letter is in that string. The string can contain characters other than letters, but only the letters should be counted. The string could even be the empty string. Lower-case and upper-case versions of a letter should be part of the same count. The keys of the dictionary should be the upper-case letters. If a letter does not...

  • Write a static method called encodeString that takes a string as input and prints to the...

    Write a static method called encodeString that takes a string as input and prints to the console a word where each letter is advanced by one value. In addition, your method should return the encoded String. You may make use of the method provided below to help you. public static char encode(char x) { int current = x; current++; return (char)current; } This method takes a character and returns an "encoded" character. In other words, encode('a') will return 'b'. Your...

  • Write a method will accept an array of Strings. This method should return the string that...

    Write a method will accept an array of Strings. This method should return the string that comes after all the other strings in lexicographical order. (Assume all the Strings only contain lower case letters. In Example: No number, no Capitals and no Symbols) lastString({“hola”, “word”, “night”, “boom”}) → “word” lastString({“java”, “is”, “so”, “much”, “fun”}) → “so” lastString({“i”, “love”, “java”}) → “love” //precondition: words.length >0 public static String lastString(String[] words) { }

  • ​​​​​​public static int countCharacter(String str, char c) { // This recursive method takes a String and...

    ​​​​​​public static int countCharacter(String str, char c) { // This recursive method takes a String and a char as parameters and // returns the number of times the char appears in the String. You may // use the function charAt(int i) described below to test if a single // character of the input String matches the input char. // For example, countCharacter(“bobbie”, ‘b’) would return back 3, while // countCharacter(“xyzzy”, ‘y’) would return back 2. // Must be a RECURSIVE...

  • Write a static method called printWithSpaces that takes a String as its parameter and prints the...

    Write a static method called printWithSpaces that takes a String as its parameter and prints the characters of the string separated by spaces. For example: > Methods.printWithSpaces("method") m e t h o d You should have a single space after the last character. This method should not return a value. That is similar to this code for printing the string vertically public static void printVertical(String s) { for (int i = 0; i < s.length(); i++) { char c =...

  • Create a public static method named valueG that takes an ArrayList of type Double and returns...

    Create a public static method named valueG that takes an ArrayList of type Double and returns a double. This method returns the maximum result ( do not return the original value) of taking the sine of each value from the input

  • package week_3; /** Write a method called countUppercase that takes a String array argument. You can...

    package week_3; /** Write a method called countUppercase that takes a String array argument. You can assume that every element in the array is a one-letter String, for example String[] test = { "a", "B", "c", "D", "e"}; This method will count the number of uppercase letters from the set A through Z in the array, and return that number. So for the example array above, your method will return 2. You will need to use some Java library methods....

  • JAVA Overview Create a method public static void spongeBobify(String inputPath, String outputPath...

    JAVA Overview Create a method public static void spongeBobify(String inputPath, String outputPath, Mode mode) that will convert a file to Mocking Sponge Bob text in 3 different modes. EveryOther capitalize the first letter of the string capitalize every other letter (ignoring non-letter character like punctuation and spaces). non-letter characters don't count toward the every other count Example: mocking sponge bob! → MoCkInG sPoNgE bOb! Vowels capitalize every vowel (not including y) Random capitalize each letter with a probability of 35%....

  • 2. public static string trim(String str) This method should take a string str and use recursion...

    2. public static string trim(String str) This method should take a string str and use recursion to return a string in which any leading and/or trailing spaces in the original string are removed. For example: trim(" hello world ") should return the string "hello world" trim("recursion ") should return the string "recursion" The String class comes with a built-in trim() method that does the same thing as the method that we're asking you to write; you may not use that...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT