

下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、java_java構(gòu)建計算器(帶開關(guān))我正在使個開關(guān)計算兩個數(shù)字,但是當(dāng)我嘗試做任何類型的運(yùn)算符時,我只是繼續(xù)0。/importsimport java.util.Scanner;public class Calculator public static void main (String args) /get first numberScanner scan = new Scanner(System.in);System.out.println(Please enter the first number: );int num1 = scan.nextInt();/ get second nu
2、mberSystem.out.println(Please enter the second number: );int num2 = scan.nextInt();/ what the user wants to doSystem.out.println(Please enter the method you would like to use + (+ , - , * , / , ) );String method = scan.next();char operation = method.charAt(0);String output = ;/switch for first numbe
3、rswitch(num1) case 0:output+= zero;break;case 1:output+= one;break;case 2:output+= two;break;case 3:output+= three;break;case 4:output+= four;break;case 5:output+= five;break;case 6:output+= six;break;case 7:output+= seven;break;case 8:output+= eight;break;case 9:output+= nine;break;case 10:output+=
4、 ten;break;/ operation the user wants to useswitch (operation)case + : output += plus;break;case - : output += minus;break;case * : output += times;break;case / : output += divided by;break;case : output += to the power of;break;/switch for second numberswitch (num2) case 0:output += zero;break;case
5、 1:output += one;break;case 2:output += two;break;case 3:output += three;break;case 4:output += four;break;case 5:output += five;break;case 6:output += six;break;case 7:output += seven;break;case 8:output += eight;break;case 9:output += nine;break;case 10:output += ten;break;/ calculate the answerin
6、t answer = 0 ;switch (answer) case + : answer = (answer + (num1 + num2);break;case - : answer = (answer + (num1 - num2);break;case * : answer = (answer + (num1 * num2);break;case / : answer = (answer + (num1 / num2);break;case : answer = (answer + (int) (Math.pow(num1,num2) );break;System.out.println(output + equals + answer );我很
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 馬超出軌離婚賠償合同附詳細(xì)合同范本
- 醫(yī)療機(jī)構(gòu)護(hù)理人員聘用合同范文
- 展會攤位租賃合同樣本
- 公司勞動合同與晉升激勵政策完整版范本
- 統(tǒng)一住宅買賣合同文本
- 建筑工程施工合同安全協(xié)議書
- 建筑工程水電安裝分包合同范本
- 土地流轉(zhuǎn)轉(zhuǎn)租正式合同
- 簽訂新海家園D區(qū)2#303房屋租賃合同
- 度個人工程承包合同之二:權(quán)益保障
- 【海信電器員工流失現(xiàn)狀調(diào)查及其原因和完善策略10000字】
- 小學(xué)美術(shù)人教版三年級下冊 .動物的花衣裳 教學(xué)課件
- 國資公司招聘總經(jīng)理試題
- 天津醫(yī)院運(yùn)營分析報告
- 呼吸科健康宣教五分鐘
- 消化道出血病人健康教育課件
- 《橋梁施工方法掛籃》課件
- 《關(guān)于情商的》課件
- 2024年國家能源集團(tuán)招聘筆試參考題庫含答案解析
- 2024版行政管理培訓(xùn)課件
- 錨固溝施工方案
評論
0/150
提交評論