活学活用吧
句子逆序
http://www.nowcoder.com/questionTerminal/48b3cb4e3c694d9da5526e6255bb73c3
import java.util.*; public class Main{ public static void main(String[] agrs){ Scanner in = new Scanner(System.in); String input = in.nextLine(); System.out.println(getResult(input)); } public static String getResult(String input) { StringBuilder sb = new StringBuilder(); Stack<String> stack = new Stack<>(); String[] arr = input.split("\\s"); for (String str : arr) { stack.push(str); } while (!stack.isEmpty()) { sb.append(stack.pop() + " "); } return sb.toString(); } }