02_简单计算器实现
public class Demo {
public static void main(String[] args) {
int flag = 0;
while(flag != 5){
System.out.println("选择加法请按1,2,3,4"+"\t"+"退出请按5");
Scanner scanner = new Scanner(System.in);
int c = scanner.nextInt();
switch(c) {
case 1:
System.out.println("请输入第一个数a:");
Scanner scanner1 = new Scanner(System.in);
double a = scanner1.nextDouble();
System.out.println("请输入第2个数b:");
Scanner scanner2 = new Scanner(System.in);
double b = scanner2.nextDouble();
Demo demo = new Demo();
double sum = Demo.add(a, b);
System.out.println("结果为" + sum);
// scanner1.close();
// scanner2.close();
break;
case 5:
flag = 5;
break;
}
// scanner.close();
}
}
public static double add(double a, double b) {
return a + b;
}
public static double sub(double a, double b) {
return a - b;
}
public static double mul(double a, double b) {
return a * b;
}
public static double div(double a, double b) {
return a / b;
}
}
标签:Scanner,16,double,简单,System,static,计算器,public,out
From: https://www.cnblogs.com/DivineBrightness/p/18278958