运用java的基本库类,实现一个计算四则运算的程序
答案:1 悬赏:70 手机版
解决时间 2021-05-13 15:39
- 提问者网友:嘚啵嘚啵
- 2021-05-13 06:05
运用java的基本库类,实现一个计算四则运算的程序
最佳答案
- 五星知识达人网友:青尢
- 2021-05-13 07:08
package Ex1; //Ex1为包名
import java.util.*;
public class SzYs { //SzYs为类名
public static void main(String[] args){
double num1;
double num2;
String fuHao;
Scanner input = new Scanner(System.in);
System.out.print("输入第一个数的值:");
num1 = input.nextDouble();
System.out.print("输入第二个数的值:");
num2 = input.nextDouble();
System.out.print("输入运算符号(+ - * \\ )");
fuHao = input.next();
if(fuHao.equals("+")){
System.out.print(num1 + "与" + num2 + "的和是" + (num1+num2));
}else if(fuHao.equals("-")){
System.out.print(num1 + "与" + num2 + "的差是" + (num1-num2));
}else if(fuHao.equals("8")){
System.out.print(num1 + "与" + num2 + "的积是" + (num1*num2));
}else if(fuHao.equals("\\")){
if(num2==0){
System.out.print("除数不能为0");
}else{
System.out.print(num1 + "与" + num2 + "的商是" + (num1/num2));
}
}else{
System.out.print("不能辨认该符号");
}
}
}
import java.util.*;
public class SzYs { //SzYs为类名
public static void main(String[] args){
double num1;
double num2;
String fuHao;
Scanner input = new Scanner(System.in);
System.out.print("输入第一个数的值:");
num1 = input.nextDouble();
System.out.print("输入第二个数的值:");
num2 = input.nextDouble();
System.out.print("输入运算符号(+ - * \\ )");
fuHao = input.next();
if(fuHao.equals("+")){
System.out.print(num1 + "与" + num2 + "的和是" + (num1+num2));
}else if(fuHao.equals("-")){
System.out.print(num1 + "与" + num2 + "的差是" + (num1-num2));
}else if(fuHao.equals("8")){
System.out.print(num1 + "与" + num2 + "的积是" + (num1*num2));
}else if(fuHao.equals("\\")){
if(num2==0){
System.out.print("除数不能为0");
}else{
System.out.print(num1 + "与" + num2 + "的商是" + (num1/num2));
}
}else{
System.out.print("不能辨认该符号");
}
}
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯