题解 | #句子逆序#
句子逆序
https://www.nowcoder.com/practice/48b3cb4e3c694d9da5526e6255bb73c3
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String str=in.nextLine(); String[] words =str.split(" "); int n=words.length; //for(int i=n-1;i>=0;){ // System.out.print(words[i--]+" "); //暴力循环输出 //} java.util.List<String> list = java.util.Arrays.asList(words);//先将数组转换成列表 java.util.Collections.reverse(list);//再用反转函数 for (String num : list) { System.out.print(num + " "); } } }