在字符串中不起作用

时间:2019-03-01 19:09:34

标签: java while-loop do-while

我有此代码:

public static void main(String[] args) {
    double Guillermo, Luis, Juan;
    Scanner in = new Scanner(System.in);
    String exit = "";

    do {
        System.out.print("Cuanto tiene Guillermo: ");
        Guillermo = in.nextDouble();

        Luis = Guillermo / 2;
        Juan = (Guillermo + Luis) / 2;

        System.out.println("Guillermo tiene: " + Guillermo + " dolares");
        System.out.println("Luis tiene: " + Luis + " dolares");
        System.out.println("Juan tiene: " + Juan + " dolares");

        System.out.println("Desea repetir: Y/N ");
        exit = in.nextLine();

    } while (exit.equals("y"));

}

因此,当我运行该程序时,可以正常工作,但是在最后一行“ Desea repetir:是/否”中,我没问我,只是跳过了这一部分,程序便结束了。

0 个答案:

没有答案