下面按顺序打印出输入的句子。我需要它以相反的顺序打印输入:
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);
}
}
}
PIPIONE
明月笑刀无情
隔江千里
相关分类