import java.util.ArrayDeque; import java.util.Scanner; public class Main { public static void main(String[] args) { ArrayDeque deque = new ArrayDeque(); Scanner scanner = new Scanner(System.in); while (scanner.hasNext()) { String name = scanner.next(); // 初始化队列中的数据 deque.offerLast(name); } // write your code here...... Boolean flag = true; //表示奇偶,奇偶出队分别是首尾 while (!deque.isEmpty()) { //队列没有人为止 if (flag) { //弹队首 System.out.println(deque.getFirst()); deque.removeFirst(); flag = false; //交替 } else { //弹队尾 System.out.println(deque.getLast()); deque.removeLast(); flag = true; //交替 } } } }