The following prints out the entered sentence in order. I need it to print the input in reverse order:
import java.util.Scanner;
public class Sentence {
public static void main(String [] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a sentence: ");
String sentence = input.nextLine();
String[] tokens = sentence.split(" ");
System.out.println(tokens.length);
for (String token : tokens) {
System.out.println(token);
}
}
}