我怎样才能重新写这个,所以我不使用 while(true) 循环?我需要打破 while 循环条件的方法,但我似乎无法解决。
ArrayList<Account> accounts = new ArrayList<Account>();
public void enterCustomers()
{
System.out.println("Enter customer names or q to quit entering names");
while(true)
{
Scanner scan = new Scanner(System.in); //find alternative to while true
System.out.print("Enter a customer name: ");
String name = scan.nextLine();
if(name.equalsIgnoreCase("q"))
{
break;
}
System.out.print("Enter openning balance: ");
Double balance = scan.nextDouble();
Account a = new Account(name, balance);
accounts.add(a);}
}
慕森卡
相关分类