Answered You can hire a professional tutor to get the answer.

QUESTION

Please keep it simple, Use only the notes above, do the following : Complete the method numWords() that accepts a string and returns the number of...

Please keep it simple,

Use only the notes above, do the following :

1. Complete the method numWords() that accepts a string and returns the number of words in the string.

2. Complete the method getLastWord() that accepts a string and returns the last word in the string.

3. Complete the method alternateCase() that accepts a String and returns a new String with alternating case. For example:

Input: ""String Programming in Java is fun"

Return value: "StRiNg pRoGrAmMiNg iN JaVa iS FuN"

4. Complete the method printIndices that accepts a String source and a character search, and prints the position of each occurrence of the search value in source. For example:

Input: source = "String Programming in Java is fun", search = 'i'

Console Output: 3 15 19 27

Here is the incomplete source code below:

/**

*

* @author

*

*/

public class StringsPairProgram {

  /**

  *

  * @param sentence

  * @return

  */

  public static int numWords(String sentence) {

     return 0 ;

  }

/**

*

* @param sentence

* @return

*/

  public static String getLastWord(String sentence) {

     return "";

  }

/**

*

* @param sentence

* @return

*/

  public static String alternateCase(String sentence) {

     return "";

  }

  public static void printIndices(String source, char search) {

  }

/**

*

* @param args

*/

  public static void main(String[] args) {

     String sentence = "String Programming in Java is fun";

     System.out.println("Expected numWords() returns 6 : " + numWords(sentence));

     System.out.println("Expected getLastWord() returns fun : " + getLastWord(sentence));

     System.out.println(

           "Expected alternateCase() returns StRiNg pRoGrAmMiNg iN JaVa iS FuN : " + alternateCase(sentence));

     System.out.println("Expected printIndices() prints indices 3 15 19 27 for search letter i : ");

     printIndices(sentence, 'i');

  }

}

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question