1 package com.lin.method; 2 3 import java.util.Scanner; 4 5 public class Demo6 { 6 public static void main(String[] args) { 7 Scanner scanner = new Scanner(System.in); 8 double num1 = scanner.nextDouble(); 9 String formula = scanner.next(); 10 double num2 = scanner.nextDouble(); 11 switch (formula) { 12 case "+": 13 System.out.println(num1+num2); 14 break; 15 case "-": 16 System.out.println(num1-num2); 17 break; 18 case "*": 19 System.out.println(num1*num2); 20 break; 21 case "/": 22 System.out.println(num1/num2); 23 break; 24 } 25 scanner.close(); 26 } 27 }
原文:https://www.cnblogs.com/summerday0903/p/14402029.html