java简易计算器程序代码
时间: 2023-11-04 12:54:05 浏览: 109
java简易计算器代码
代码如下:
```java
import java.util.Scanner;
public class CalculatorTest {
public static void main(String[] args) {
while (true) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入第一个数字:");
int numberOne = scanner.nextInt();
System.out.println("请输入第二个数字:");
int numberTwo = scanner.nextInt();
System.out.println("请输入符号 + - * /");
String symbol = scanner.next();
switch (symbol) {
case "+":
System.out.println("计算结果:" + (numberOne + numberTwo));
break;
case "-":
System.out.println("计算结果:" + (numberOne - numberTwo));
break;
case "*":
System.out.println("计算结果:" + (numberOne * numberTwo));
break;
case "/":
System.out.println("计算结果:" + (numberOne / numberTwo));
break;
default:
System.out.println("符号错误请重新输入...");
}
System.out.println("本次程序计算完成,开始下一次计算------");
}
}
}
```
阅读全文