我怎样才能重新写这个,所以我不使用 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);}
}
慕森卡
如何避免循环变量的引用的?
像C ++这样的Python中的无限for循环
如何在反序列化过程中不使用无限循环的情况下编写kafka消费者?
关于用for循环来完成append的问题
相关分类