Question

* Creates a string that displays the first position of the letters a, e, i, * o, and u in sentence. If a vowel is not located

0 0
Add a comment Improve this question Transcribed image text
Answer #1
public class VowelIndices {

    public static String findVowels(String sentence) {
        return String.format(
                "The first position of a is %d.\n" +
                        "The first position of e is %d.\n" +
                        "The first position of i is %d.\n" +
                        "The first position of o is %d.\n" +
                        "The first position of u is %d.\n",
                sentence.indexOf('a'),
                sentence.indexOf('e'),
                sentence.indexOf('i'),
                sentence.indexOf('o'),
                sentence.indexOf('u'));
    }

    public static void main(String[] args) {
        System.out.println(findVowels("appleapp"));
    }
}

The first position of a is 0. The first position of e is 4. The first position of i is -1. The first position of o is -1. The

Add a comment
Know the answer?
Add Answer to:
* Creates a string that displays the first position of the letters a, e, i, *...
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
  • Here is the indexOf method that I wrote: public static int indexOf(char[] arr, char ch) {...

    Here is the indexOf method that I wrote: public static int indexOf(char[] arr, char ch) {            if(arr == null || arr.length == 0) {                return -1;            }            for (int i = 0; i < arr.length; i++) {                if(arr[i] == ch) {                    return i;                }            }        return -1;       ...

  • Restrictions: You may not change any of the fields, nor the constructor, nor the insertAtFront method....

    Restrictions: You may not change any of the fields, nor the constructor, nor the insertAtFront method. As usual, you may not modify the method headers given to you in any way nor may you change the name of the class or the package. You must use recursion to solve the problems. Your code may not contain any loops. Functions that have loops will receive 0 points package hw8; import java.util.NoSuchElementException; public class MyList<Item> { private class MyListNode { public Item...

  • Java Here is the template public class ShiftNumbers { public static void main(String[] args) { // TODO:...

    Java Here is the template public class ShiftNumbers { public static void main(String[] args) { // TODO: Declare matrix shell size // TODO: Create first row // TODO: Generate remaining rows // TODO: Display matrix } /** * firstRow * * This will generate the first row of the matrix, given the size n. The * elements of this row will be the values from 1 to n * * @param size int Desired size of the array * @return...

  • Given the following classes: StringTools.java: public class StringTools { public static String reverse(String s){ char[] original=s.toCharArray();...

    Given the following classes: StringTools.java: public class StringTools { public static String reverse(String s){ char[] original=s.toCharArray(); char[] reverse = new char[original.length]; for(int i =0; i<s.length(); i++){ reverse[i] = original[original.length-1-i]; } return new String(reverse); } /**  * Takes in a string containing a first, middle and last name in that order.  * For example Amith Mamidi Reddy to A. M. Reddy.  * If there are not three words in the string then the method will return null  * @param name in...

  • import java.util.Arrays; import java.util.Random; import java.util.Scanner; /** * TODO Write a summary of the role of...

    import java.util.Arrays; import java.util.Random; import java.util.Scanner; /** * TODO Write a summary of the role of this class in the * MasterMind program. * * @author TODO add your name here */ public class MasterMind { /** * Prompts the user for a value by displaying prompt. * Note: This method should not add a new line to the output of prompt. * * After prompting the user, the method will consume an entire * line of input while reading...

  • I need help filling in the the code in the methods add, multiply, and evaluate package...

    I need help filling in the the code in the methods add, multiply, and evaluate package poly; import java.io.IOException; import java.util.Scanner; /** * This class implements evaluate, add and multiply for polynomials. * * * */ public class Polynomial {       /**    * Reads a polynomial from an input stream (file or keyboard). The storage format    * of the polynomial is:    * <pre>    * <coeff> <degree>    * <coeff> <degree>    * ...    *...

  • Load to the IDEA the remaining classes from the provided Lab02.zip file. Repeat the previous project...

    Load to the IDEA the remaining classes from the provided Lab02.zip file. Repeat the previous project inside the ArraySetWithArray class. As shown in the UML diagram below ArraySetWithArray class does not utilize ResizableArrayBag object as its instance variable, it has setOfEntries defined as an array which should be dynamically resized if more room needed (double the size). displaySet method should check if the set is empty and display appropriate message; if the set is not empty should display the number...

  • String variables/Selection & loop Write a complete Java program which prompts the user for a sentence on one line wh...

    String variables/Selection & loop Write a complete Java program which prompts the user for a sentence on one line where each word is separated by one space, reads the line into one String variable using nextline(), converts the string into Ubbi dubbi and displays the translated sentence. Ubbi dubbi works by adding ub before each vowel sound in a syllable. For example, hello becomes hubellubo. The word speak has the vowel sound ea, so in Ubbi dubbi it becomes spubeak....

  • Please help me with me. I did the first part to write the operations but in...

    Please help me with me. I did the first part to write the operations but in the driver its shows me errors, can't fix it. Help me. Need help with this to run the application. /** * BinaryTreeNode represents a node in a binary tree with a left and * right child. * * @author Java Foundations * @version 4.0 */ public class BinaryTreeNode { protected T element; protected BinaryTreeNode left, right; /** * Creates a new tree node with...

  • Hey, I was wondering if there’s another way to make these methods not reliable to imports...

    Hey, I was wondering if there’s another way to make these methods not reliable to imports such as “import java.util.Arrays” and “import java.util.Hash” I am still new in coding and would like to know if there’s another way to do it! Here is the code! (Thank you in advance and I will really appreciate it :) ) /** This exercise involves implementing several methods. Stubs for each method with documentation are given here. It is your task to fill out...

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