public int Run(String s)
{
int len = s.length(); //字符串长度len
int n=0;
int i=1;

for (i=1;i<=len;i++)
{
if (s.charAt(i)=='+'||s.charAt(i)=='-'||s.charAt(i)=='*'||s.charAt(i)=='/')
{n=n+1;}
}
int factor[] =new int[n+1]; //每个运算因子作为一个factor存在
int act[] = new int[n]; //运算符号99个


int posa=1;int posb=1; //截取位置符

int fi=1;int ai=1; //运算因子号数,运算符号号数
int ans=0;
i=1;
for (i=1;i<=len;i++) //提取运算因子和运算符号循环
{
char temps = s.charAt(i); //当前指针符
if (temps =='+'||temps=='-'||temps=='*'||temps=='/')
{
posb=i-1;
factor[fi]=Integer.parseInt(s.substring(posa,posb)); //提取运算因子
posa=i+1;
fi=fi+1;


if (temps == '+'){act[ai]=1;}
else if (temps == '-'){act[ai]=2;}
else if (temps == '*'){act[ai]=3;}
else if (temps == '/'){act[ai]=4;}

ai=ai+1; 
}
}

ans=factor[1];

if(ai!=1){
for (i=2;i<=ai+1;i++) //运算循环
{
if (act[i-1] == 1){ans=ans+factor[i];}
else if (act[i-1] == 2){ans=ans-factor[i];}
else if (act[i-1] == 3){ans=ans*factor[i];}
else if (act[i-1] == 4){ans=ans/factor[i];}
}
}
return ans;
}
目标:是调用Run函数,输入一个字符串例如"213+123*567-234/35",返回一个答案ans;当输入上述例子提示: StringIndexOutOfBoundsException: String index out of range: 18求解??万分感谢