Question: please complete the following java problem // ym 1 import java.util.Scanner; 2 // Use a scanner and read each word from a string that contains
please complete the following java problem

// ym 1 import java.util.Scanner; 2 // Use a scanner and read each word from a string that contains multiple words. 4 // Print each word in reverse order 5 // then reverse the reversed word to get back the original word, print it 6 // For Example: "hello my name is Inigo Montoya" would result in 7 7 // olleh 8 8 // Hello 9 10 // my 11 // eman 12 // name 13 // si 14 // is 15 // ogini 16 // Inigo 17 // ayotnom 18 // Montoya 19 20 public class ReverseWords 21 { 22e public static void main(String[] args) 23 24 String words = "A quick brown fox jumps over the lazy alligator"; 25 Scanner in = new Scanner(words); 26 27 while (in.hasNext() 28 { 29 String word = in.next(); 30 31 --Start below here. To do: approximate lines of code = 4 32 1/ 1. You must use a for loop and the charAt() method of class String to 33 // store the reversed word into a string and then print the reversed word 34 1/ Hint: count down rather than up in the for loop (i.e. start at the end of the word) 35 36 37 38 39 40 41 42 -End here. Please do not remove this comment. Reminder: no changes outside the todo regions. -Start below here. To do: approximate lines of code = 4 1/ 2. now repeat the reversing loop but use the reversed word from above as input // print the word - it should now be back to its original order 43 44 45 46 47 48 49 50 51 52 53 54 55 ) 56 --End here. Please do not remove this comment. Reminder: no changes outside the todo regions. } System.out.println("Expected: A A kciuq quick nworb brown xof fox spmuj jumps revo over eht the yzal lazy rotagilla alligator"); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
