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时,它什么也没做。