可以看下代码有什么问题部’
double sum = 0 ;
String str2 =str1.substring(0,str1.indexOf(" "));
String op = str1.substring(str1.indexOf("")+1,str1.indexOf("")+2);
String str3 = str1.substring(str1.indexOf(" ")+3);
if(!str2.equals("")&&!str3.equals(""))
{
double num1 = Double.parseDouble(str2);
double num2 = Double.parseDouble(str3);
if(op.equals(" + "))
{
sum = num1+num2;
}
else if(op.equals(" - "))
{
sum = num1- num2;
}
else if(op.equals(" × "))
{
sum = num1 * num2;
}
else if(op.equals(" ÷ ")) {
if (num2 == 0) {
sum = 0;
} else {
sum = num1 / num2;
}
}
}