我会逐渐改善
package demo;
import java.util.Scanner;
public class demo14 {
public static void main(String[] args) {
// 14. 编写一个计算器控制台程序。
Scanner sc = new Scanner(System.in);
System.out.println("请输入第一个数");
double x = sc.nextInt();
System.out.println("请选择四则运算");
System.out.print("加法输入1"+" ");
System.out.print("减法输入2"+" ");
System.out.print("乘法输入3"+" ");
System.out.println("除法输入4");
int suan = sc.nextInt();
if (suan ==1 || suan == 2 || suan == 3 ||suan == 4) {
System.out.println("请输入第二个数");
double y = sc.nextInt();
if (suan == 1) {
System.out.println(+x+"+"+y+"=" + (x + y));
} else if (suan == 2) {
System.out.println(+x+"-"+y+"=" + (x - y));
} else if (suan == 3) {
System.out.println(+x+"*"+y+"=" + (x * y));
} else {
System.out.println(+x+"/"+y+"=" + (x / y));
}
} else {
System.out.println("输入错误");
}
}
}
运行结果
逐渐改进!!1