0

我希望程序清除以前的控制台输出。例如,我有一个数据输入程序,当程序重复时,输入的整个输出必须在控制台中擦除以保护隐私(例如,如果您不认识的人再次使用该程序而您没有希望他们看到您之前在控制台中输入的内容)。顺便说一句,我在 Eclipse 中使用 Java,我想知道这件事是否可能。

    String aWord;
    String repeat;
    do {

    Scanner scan = new Scanner(System.in);




    System.out.println("Type anything.");
    aWord = scan.nextLine();

    System.out.println("Do you want to type anything again? Y/N");
    repeat = scan.nextLine();

    while(!repeat.equalsIgnoreCase("y") && !repeat.equalsIgnoreCase("n")) {
            System.out.println("[ERROR] Please answer correctly.");
            repeat = scan.nextLine();
            if (repeat.equalsIgnoreCase("n")) {
                System.out.println("Thanks for using this program!");
                System.exit(0);
            }
        }

    if (repeat.equalsIgnoreCase("n")) {
        System.out.println("Thanks for using this program!");
        System.exit(0);
    }


    }while (repeat.equalsIgnoreCase("y"));
        // if the user answers yes, the program must repeat the whole process.
        // if the user answers yes, the program must wipe out all previous output in the console.
4

0 回答 0