大家好,这是我的代码,它正在做一个循环,但是它要做的是,如果用户键入借款,它将询问用户它做了多少,但是他们键入一个数字,它将再次询问他们您想借还是卖,这是一个无限循环。
case 3:
do{
System.out.println("What would you like to do? Please type borrow to borrow money or sell to sell assets: ");
b = scan.nextLine().toLowerCase();
if(b.equals("borrow")){
System.out.print("how much would you like to borrow Remmber if you go over 50000 debt its game over.");
try {
input = scan.nextInt();
} catch (Exception e) {
System.err.println("That is not a number!!");
}
account.setdebt(account.getDebt() + input);
account.setBalance(account.getBalance() + input);
System.out.println("Your new Balance is " + account.getBalance());
}
else if(b.equals("sell")){
sellA();
}else{
System.out.println("You didn't input 'borrow' or 'sell'. Reinput please");
}
}while(!b.equals("borrow") || !b.equals("sell"));
break;
最佳答案
您需要在||
内部将&&
更改为while
,否则条件始终为true。 b
不等于的那两个值中至少会有一个。