如何使用字符串打印堆栈,以哨兵结束

时间:2015-10-20 01:53:14

标签: java string stack

如何让它运行?我有一个堆栈,我将String推入堆栈,我打印堆栈,我是否还要弹出堆栈以使其运行?

import java.util.*;

public class Stacks {
    public static void main(String args) {
        Scanner input = new Scanner(System.in);
        String words;
        String DONE = null;
        Stack<String> series = new Stack<String>();
        System.out.println("Enter a series of words or 'DONE' to quit");
        words = input.nextLine();
        series.push(words);

        while (!words.equals("DONE")) {
            System.out.println(series);
            System.out.println("Enter a series of words or 'DONE' to quit");
            words = input.nextLine();

            if (words.equals("DONE")) {
                break;
            }
        }
    }
}

0 个答案:

没有答案