Many times, you have used
Scannermethods to read and parse keyboard input. You can also use those same
Scannermethods to read and parse an ordinary
String.The text’s
printReverseMessagemethod in Figure 11.7 used
String’s charAtmethod to reverse the order of the letters in a string. This exercise asks you to use
Scanner’s nextmethod to reverse the order of the words in a string. The program below should reverse the words in the string, “We Are Many,” and return the string, “Many Are We.” In the recursive method in this program, supply the code where it says <code-fragment>.
import java.util.Scanner;public class ReverseWords{ public static void main (String[] args) { String message = new String ("We Are Many"); Scanner scan = new Scanner (message); String reversedMessage = getReverse (scan); System.out.println (reversedMessage); } // end main //************************************************** public static String getReverse (Scanner scan) { String nextWord; <code-fragment> } // end getReverse} // end class ReverseWordsDo not use an array. Use
Scanner’s nextmethod to step through the message in the
scanobject, retrieve each
nextWord,and
returnthe return from a recursive call plus that
nextWord.What changes with each recursive call? What is the stopping condition? What does the
getReversemethod return when the stopping condition is satisfied?
Figure Recursive implementation of the printReverseMessage method

We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.