package com.plato.method;
import java.util.Scanner;
public class MethodDemo03 {
public static void main(String[] args) {
//简易计算器
Scanner scanner = new Scanner(System.in);
double a = scanner.nextDouble(); //输入完后回车表示输入结束。
char op = scanner.next().charAt(0);
double b = scanner.nextDouble();
operator(op, a, b); //方法里用到的参数必须都传递过去,不然方法解析不了没传过去的参数。
scanner.close();
}
//判断运算种类
public static void operator(char op, double a, double b) { //void无返回值
switch (op) {
case '+':
System.out.printf("%f", a + b); //输出浮点数用f;要用格式转换符输出需要用printf
break;
case '-':
System.out.printf("%f", a - b);
break;
case '*':
System.out.printf("%f", a * b);
break;
case '/':
System.out.printf("%f", a / b);
break;
default:
System.out.println("只能计算加减乘除!");
}
}
}