在这之前想了很多功能,最终不能实现而放弃了
-
- 想实现多数字的加减乘除(结果不会拆字符串,放弃了)
-
- 想实现一条字符串进行计算,如"5*55"(结果不会拆字符串,放弃了)
package com.xiao.method;
import java.util.Scanner;
public class Calculator {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请收入第一个数:");
double a =scanner.nextDouble();
System.out.println("请收入一个四则运算符号:");
String x =scanner.next();
System.out.println("请收入第二个数:");
double b =scanner.nextDouble();
judgment(a,b,x);
scanner.close();
}
public static void judgment(double a,double b,String x) {
switch (x){
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("您输入的不属于四则运算符号");
}
}
}