题解 | #句子逆序#
句子逆序
http://www.nowcoder.com/practice/48b3cb4e3c694d9da5526e6255bb73c3
完全使用了api,没有技术含量
import java.util.Collections;
import java.util.Scanner;
/**
* @Description 句子逆序
* @Author haixiaofei
* @Date 2022/2/23 9:20
**/
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNextLine()) {
String str = in.nextLine();
String[] strings = str.split(" ");
//数组转化为list,对list逆序
Collections.reverse(Arrays.asList(strings));
StringBuilder sb = new StringBuilder();
for (int i = 0; i < strings.length; i++) {
if (i == strings.length-1) {
sb.append(strings[i]);
}else {
sb.append(strings[i]);
sb.append(" ");
}
}
System.out.println(sb);
}
}
}