第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么java忽略這一行?

為什么java忽略這一行?

蝴蝶不菲 2023-10-13 15:25:34
我正在編寫一個程序來為用戶提供一個菜單。在他輸入數(shù)字后,我使用開關(guān)來決定用戶應(yīng)該輸入哪個參數(shù)。無論如何,在一種情況下(情況1)我需要用戶的輸入。但是在用戶輸入第一個輸入后,程序會中斷開關(guān)并執(zhí)行開關(guān)之后的操作。代碼 :案例一: case 1:          System.out.println("Enter the Amount :");          currentAccount.debit(scanner.nextDouble());          System.out.println("Want anything else(yes/no)?");          String input=scanner.nextLine();          if(input.equalsIgnoreCase("no")){          isFinished=true;             currentAccount=null;          System.out.println("SignedOut successfully");            }          break;輸出:Choose an opearation: 1.withdraw.2.deposit. 3.transaction history.  1Enter the Amount :  100 Debit amount exceeded account balance. Want anything else(yes/no)? --------- Mhd Bank --------- logined as :  -------------------------------- Choose an opearation:  1.withdraw. 2.deposit.  3.transaction history.
查看完整描述

1 回答

?
森林海

TA貢獻2011條經(jīng)驗 獲得超2個贊

發(fā)生這種情況是由于線路未完全消耗Scanner之后的行為。scanner.nextDouble();


嘗試這個解決方法


case 1:

    System.out.println("Enter the Amount :");

    currentAccount.debit(scanner.nextDouble());

    scanner.nextLine();  // Consume newline left


    System.out.println("Want anything else(yes/no)?");

    String input=scanner.nextLine();


    if(input.equalsIgnoreCase("no")){

        isFinished=true;   

        currentAccount=null;

        System.out.println("SignedOut successfully");  

    }

    break;


查看完整回答
反對 回復(fù) 2023-10-13
  • 1 回答
  • 0 關(guān)注
  • 124 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號