1 public class SuanLianxi
2 {
3 public static void main(String[] args)
4 {
5 //储存数值
6 double[] shuzhi = new double[]{0,12,11,13,1,5,9};//任意取值验证这个优先级算法
7 //储存运算符
8 String[] operation = new String[]{" ","+","-","*","/"};
9 //储存运算符号对应的下标
10 int[] fuhao = new int[]{0,1,4,3,2,3};//解释:"+"->"1","-"->"2","*"->"3","/"->"4"
11 //12+11/13*1-5*9
12 double left=0;
13 double right = shuzhi[1];
14 int sign = 1;
15 for(int i=1;i<=5;i++)
16 {
17 switch(operation[fuhao[i]])
18 {
19 case "+":
20 left = left+sign*right;
21 sign=1;
22 right=shuzhi[i+1];
23 break;
24 case "-":
25 left = left+sign*right;
26 sign=-1;
27 right=shuzhi[i+1];
28 break;
29 case "*":
30 right=right*shuzhi[i+1];
31 break;
32 case "/":
33 right=right/shuzhi[i+1];
34 break;
35 }
36 }
37 System.out.println(left+sign*right);//输出结果
38 }
39 }
![](https://images0.cnblogs.com/blog2015/784420/201508/131749287702597.png)