小编Ars*_*lth的帖子

而"!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 …
Run Code Online (Sandbox Code Playgroud)

java infinite-loop do-while

0
推荐指数
1
解决办法
407
查看次数

标签 统计

do-while ×1

infinite-loop ×1

java ×1