import java.util.Scanner; public class Demo06 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String y = "Y"; while (y.equals("Y")){ System.out.println("请输入第一个数"); double num1 = scanner.nextDouble(); System.out.println("请输入计算方式"); String x = scanner.next(); System.out.println("请输入第二个数"); double num2 = scanner.nextDouble(); double result = 0.0; switch (x){ case "+": result = add(num1,num2); break; case "-": result = jian(num1,num2); break; case "*": result = cheng(num1,num2); break; case "/": result = chu(num1,num2); default: System.out.println("输出有误"); } System.out.println(num1+x+num2+"="+result); System.out.println("是否继续(Y/N)"); y = scanner.next(); } scanner.close(); System.out.println("欢迎再次使用计算机"); } public static double add(double a,double b){ return a+b;} public static double jian(double c,double d){ return c-d; } public static double cheng(double e,double f){ return e*f; } public static double chu(double g,double h){ return g/h; } }
标签:scanner,Java,07,num2,double,System,计算器,println,out From: https://www.cnblogs.com/sankouyitouju/p/17837195.html