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

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

在Java Calculator程序中執(zhí)行do while循環(huán)

在Java Calculator程序中執(zhí)行do while循環(huán)

慕慕森 2021-05-03 17:53:40
在我的Java程序中,我使用了布爾變量“ decision”,該變量僅在變量為true時才應(yīng)在“ do循環(huán)代碼塊”中執(zhí)行實際的計算器代碼,但是即使決策變量為錯誤的。我正在使用Java和JDK 10的Eclipse IDE(均為最新版本)。請幫我解決。代碼如下import java.util.Scanner;public class apples {public static void main(String[] args) {    int option,a,b,c;    boolean decision;    System.out.println("We are here to create a calculator");    System.out.print("Do you want to switch on the calculator:");    Scanner yogi = new Scanner(System.in);    decision = yogi.nextBoolean();    do {        System.out.println("Following operations are available to perform:");        System.out.println("1. Addition");        System.out.println("2. Subtraction");        System.out.println("3. Multiplication");        System.out.println("4. Division");        System.out.print("Enter the operations do you want to perform:");        option = yogi.nextInt();        System.out.println("Choice of operation is:"+option);        switch(option) {        case 1:            System.out.println("Enter two numbers to be added:");            a = yogi.nextInt();            b = yogi.nextInt();            c = a + b;            System.out.print("Addition:"+c);            break;        case 2:            System.out.println("Enter two numbers to be subtracted:");            a = yogi.nextInt();            b = yogi.nextInt();            c = a - b;            System.out.print("subtracted:"+c);            break;        case 3:            System.out.println("Enter two numbers to be multiplied:");            a = yogi.nextInt();            b = yogi.nextInt();            c = a * b;            System.out.print("multiplied:"+c);            break;        case 4:            System.out.println("Enter two numbers to be divided:");            a = yogi.nextInt();            b = yogi.nextInt();            c = a / b;            System.out.print("divided:"+c);            break;        default:            System.out.println("This is a wrong choice");            break;        }    }while(decision==true);  }}
查看完整描述

2 回答

?
冉冉說

TA貢獻(xiàn)1877條經(jīng)驗 獲得超1個贊

您可以添加另一個,case 5并在該寫入System.exit(0)中成功終止程序。

while部分通過(option != 5)。這應(yīng)該運行該程序。您不需要決策變量。


查看完整回答
反對 回復(fù) 2021-05-12
  • 2 回答
  • 0 關(guān)注
  • 111 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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