import java.util.*; public class Main { //定义一个数组进行存储 static String[] arr; static int i = -1; //进行判断 private static double exp() { i++; switch (arr[i]) { case "+": return exp() + exp(); case "-": return exp() - exp(); case "*": return exp() * exp(); case "/": return exp() / exp(); default: return Double.parseDouble(arr[i]); } } //测试代码 public static void main(String[] args) { Scanner sc = new Scanner(System.in); Main m = new Main(); String str1 = sc.nextLine(); arr = str1.split(" "); //输出答案 System.out.println(m.exp()); } }