Write a program that stores a phrase as an array of words, andthen prints it backwards. The main method calls method getInput ,which asks the user how many words there are, stores them in anarray, and returns this array. printBackwards then takes this arrayof words, and prints it in reverse.
Code Example:
import java.util.Scanner;
public class L17Num1{
public static void main(String[] args) {
String[] sArray=getInput();
printBackwards(sArray);
}
public static String[] getInput()
{
System.out.println(“How many words are there?”);
Scanner scnr = new Scanner(System.in);
int num=scnr.nextInt();
String[] words = new String[num];
for (int i=0;i<num;i++){
words[i] = scnr.nextLine();
}
return words;
}
public static void printBackwards(String []w)
{
for(int i=0;i<w.length;i++)
System.out.println(w[i]);
}
}
Expert Answer
Answer to Write a program that stores a phrase as an array of words, and then prints it backwards. The main method calls method ge…