java算术测试加减乘除
时间: 2023-10-17 22:03:05 浏览: 92
好的,我可以为您提供一个简单的Java算术测试程序,可以测试加减乘除四则运算。以下是代码示例:
```
import java.util.Scanner;
public class ArithmeticTest {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int num1, num2, result;
char operator;
System.out.println("请输入第一个数字:");
num1 = scanner.nextInt();
System.out.println("请输入第二个数字:");
num2 = scanner.nextInt();
System.out.println("请输入运算符(+、-、*、/):");
operator = scanner.next().charAt(0);
switch (operator) {
case '+':
result = num1 + num2;
System.out.println(num1 + " + " + num2 + " = " + result);
break;
case '-':
result = num1 - num2;
System.out.println(num1 + " - " + num2 + " = " + result);
break;
case '*':
result = num1 * num2;
System.out.println(num1 + " * " + num2 + " = " + result);
break;
case '/':
if (num2 == 0) {
System.out.println("除数不能为0!");
break;
}
result = num1 / num2;
System.out.println(num1 + " / " + num2 + " = " + result);
break;
default:
System.out.println("您输入的运算符不正确!");
break;
}
}
}
```
您可以尝试在命令行或者集成开发环境中运行此程序,输入相应的数字和运算符,程序会计算并输出结果。
阅读全文