+-*/简单计算器
作者:互联网
package com.tang.method;
import java.util.Scanner;
public class Demo06 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入计算规则:");
String op =scanner.nextLine();
System.out.println("请输入第一个数:");
double a =scanner.nextDouble();
//String x =scanner.nextLine();
System.out.println("请输入第二个数:");
double b =scanner.nextDouble();
//String y =scanner.nextLine();
switch (op){
case "+":
System.out.println("a+b= "+(a+b));
break;
case "-":
System.out.println("a-b= "+(a-b));
break;
case "*":
System.out.println("a*b= "+(a*b));
break;
case "/":
System.out.println("a/b= "+(a/b));
break;
default:
System.out.println("输入无效");
scanner.close();
}
}
}
标签:case,scanner,计算器,System,+-,String,简单,println,out 来源: https://www.cnblogs.com/hbh-cn/p/16439140.html