eclipse简单计算器
时间: 2023-12-14 20:34:08 浏览: 149
以下是使用Java语言在Eclipse中实现简单计算器的代码示例:
```java
import java.util.Scanner;
public class Calculator {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入第一个数字:");
double num1 = scanner.nextDouble();
System.out.print("请输入第二个数字:");
double num2 = scanner.nextDouble();
System.out.print("请输入运算符(+、-、*、/):");
char operator = scanner.next().charAt(0);
double result = 0.0;
switch (operator) {
case '+':
result = num1 + num2;
break;
case '-':
result = num1 - num2;
break;
case '*':
result = num1 * num2;
break;
case '/':
result = num1 / num2;
break;
default:
System.out.println("输入的运算符不正确!");
return;
}
System.out.println("计算结果为:" + result);
}
}
```
阅读全文