import java.io.*;
class demo1{
public static void main(String[] args)throws Exception{
System.out.println("请输入第一个数字(整数):");
BufferedReader a=new BufferedReader(new InputStreamReader(System.in));
int n1 = Integer.parseInt(a.readLine());
System.out.println("请输入第二个数字(整数):");
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
int n2 = Integer.parseInt(b.readLine());
System.out.println("请输入运算符:");
char c=(char)System.in.read();
switch(c){
case '+':
System.out.println("和为:"+(n1+n2));
break;
case '-':
System.out.println("差为:"+(n1-n2));
break;
case '*':
System.out.println("积为:"+(n1*n2));
break;
case '/':
System.out.println("商为:"+(n1/n2));
break;
default:
System.out.println("用户选择错误!");
}
}
}
java中利用char字符来模拟计算器的加减乘除
最新推荐文章于 2024-08-14 21:00:35 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)