简单加减乘除计算器
package com.kuang.method; import java.util.Scanner; public class Demo07 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("请输入第一个数"); double a = scanner.nextDouble(); System.out.println("请输入运算符号"); String operation = scanner.next(); System.out.println("请输入第二个数"); double b = scanner.nextDouble(); switch (operation) { case "+": System.out.println(a + operation + b + "=" + add(a, b)); break; case "-": System.out.println(a + operation + b + "=" + sub(a, b)); break; case "*": System.out.println(a + operation + b + "=" + mul(a, b)); break; case "/": System.out.println(a + operation + b + "=" + div(a, b)); break; default: System.out.println("输入错误"); } 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; } }
标签:double,Day5,System,计算器,println,operation,out,public,加减乘除 From: https://www.cnblogs.com/actadams68/p/16892859.html