而“!b.equals(x)|| !b.equals(y)“是一个无限循环?

嘿伙计这是我的代码,它正在做的是循环,但它想要做的是如果用户键入借用然后它将询问用户它做了多少但然后他们输入一个数字,它将再次问他们你想借还是卖,它是无限循环的。

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; 

你需要改变||&&里面,否则条件总是正确的。 这两个值中至少有一个b不相等。