有人请解释为什么我的循环没有中断?

时间:2018-09-23 00:31:24

标签: java if-statement while-loop

public void enterCustomers(){

    System.out.println("Enter customer names or press q to quit entering names: ");

    while (true) {
        String name;
        double balance;
        System.out.print("Enter a customer name: ");
        name = input.next();

        System.out.print("Enter the opening balance : ");
        balance = input.nextDouble();
        accounts.add(new Account(name, balance));
        if ( name == "q") {
        break;
        }   
    }
}

我不知道为什么我的if语句无法打破循环。当我运行时按q时,它什么也没做。

0 个答案:

没有答案
相关问题