//举例:str = 1+2+3x4+7
//从字符串中查找“x”符号位置
//例子解析:x的位置为:5,所以 multiplyIndex=5
int multiplyIndex = str.indexOf("x");
//从字符串中查找“÷”符号位置
//例子解析:str中没有÷符号,所以 divideIndex=-1
int divideIndex = str.indexOf("÷");
//待计算的第一个操作索引
int firstOperationIndex = -1;
//如果没有找到乘法符号索引,那么第一个操作索引就赋值为除法符号索引
//例子解析:multiplyIndex != -1,所以这句不执行
if (multiplyIndex == -1)
firstOperationIndex = divideIndex;
//如果没有找到除法符号索引,那么第一个操作索引就赋值为乘法符号索引
//例子解析:divideIndex == -1,所以 firstOperationIndex = 5
if (divideIndex == -1)
firstOperationIndex = multiplyIndex;
//如果既没有找到乘法符号也没有找到除法符号索引,那么判断它们之间最小的索引值。
//例子解析:firstOperationIndex != -1,所以这句不执行
if (firstOperationIndex == -1)
firstOperationIndex = Math.min(multiplyIndex, divideIndex);
//查找计算符号
//例子解析:执行这句之后,operation="x"
String operation = str.substring(firstOperationIndex, firstOperationIndex+1);
//取操作符号左侧字符串
String leftE = str.substring(0, firstOperationIndex-1);
//取操作符号右侧字符串
String rightE = str.substring(firstOperationIndex+2);