Write a program that asks the user to enter a sentence it wi
Write a program that asks the user to enter a sentence; it will then print each word of the sentence in reverse. Must use arrays.
Example run:
Enter your sentence:
how are you doing
The reverse of each word in your sentence is
woh era uoy gniod ?
Solution
ReverseEachString.java
import java.util.Scanner;
 public class ReverseEachString {
  
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
 System.out.println(\"Enter your sentence: \");
 String sentence = scan.nextLine();
 String words[] = sentence.split(\" \");
     StringBuilder sb = new StringBuilder();
     for(int i=0; i<words.length; i++){
         StringBuilder wordSb = new StringBuilder(words[i]);
         sb.append(wordSb.reverse());
         sb.append(\" \");
     }
 System.out.println(\"The reverse of each word in your sentence is: \");
 System.out.println(sb.toString());
}
}
Output:
Enter your sentence:
 how are you doing
 The reverse of each word in your sentence is:
 woh era uoy gniod

