直接分隔取反即可
AC代码:
import java.util.Scanner; /**
* @author CC11001100
*/
public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in);
String s = sc.nextLine(); String[] ss = s.split("\\s+");
for(int i=ss.length-1; i>=0; i--){
System.out.print(ss[i] + (i>0 ? " " : ""));
} } }
题目来源: https://www.nowcoder.com/pat/2/problem/4075
.