欢迎来到天天文库
浏览记录
ID:8979596
大小:67.00 KB
页数:6页
时间:2018-04-13
《java 计算器实验报告》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、importjava.util.Scanner;importjava.util.*;importjava.math.*;importjava.lang.Throwable;//界面逻辑publicclassCalc{publicstaticvoidmain(String[]args){booleanflag=true;while(flag==true){System.out.println("简单计算器:");System.out.println("1.加法");System.out.println("2.减法");System.o
2、ut.println("3.乘法");System.out.println("4.除法");System.out.println("5.求余数");System.out.println("6.求一个数的平方");System.out.println("7.求一个数的立方");System.out.println("8.开平方根");System.out.println("9.求三个数中的最大值");System.out.println("10.求三个数中的最小值");System.out.println("0.退出");System
3、.out.println("请输入你的选择:");Scannersc=newScanner(System.in);intselect=sc.nextInt();if((select<0)
4、
5、(select>10)){System.out.println("输入错误,请重新输入");}else{switch(select){case0:System.out.println("已退出计算器!");System.exit(0);case1:System.out.println("以下是加法运算:");try{do{System.out.p
6、rintln("请输入任意两个数:(按任意字符退出当前计算)");Scannersc1=newScanner(System.in);floata=sc1.nextFloat();floatb=sc1.nextFloat();jisuan.plus(a,b);}while(true);}catch(InputMismatchExceptione){System.out.println("已经退出加法计算!");}break;case2:System.out.println("以下是减法运算:");try{do{System.out.p
7、rintln("请输入任意两个数:(按任意字符退出当前计算)");Scannersc2=newScanner(System.in);floatc=sc2.nextFloat();floatd=sc2.nextFloat();jisuan.minus(c,d);}while(true);}catch(InputMismatchExceptione){System.out.println("已退出减法计算!");}break;case3:System.out.println("以下是乘法运算:");try{do{System.out.p
8、rintln("请输入任意两个数:(按任意字符退出当前计算)");Scannersc3=newScanner(System.in);floate=sc3.nextFloat();floatf=sc3.nextFloat();jisuan.multiply(e,f);}while(true);}catch(InputMismatchExceptione){System.out.println("已退出乘法计算!");}break;case4:System.out.println("以下是除法运算:");try{do{System.ou
9、t.println("请输入任意两个数:(按任意字符退出当前计算)");Scannersc4=newScanner(System.in);floath=sc4.nextFloat();floati=sc4.nextFloat();jisuan.divid(h,i);}while(true);}catch(InputMismatchExceptione){System.out.println("已退出除法计算!");}break;case5:System.out.println("以下是求余运算:");try{do{System.ou
10、t.println("请输入任意两个数:(按任意字符退出当前计算)");Scannersc5=newScanner(System.in);floatj=sc5.nextFloat();floatk=sc5.nextFloat();ji
此文档下载收益归作者所有