求教:实在找不出问题在哪里了,求大神指导?

报错:else上有语法错误,请删除此标记

private void getResult(){

String exp = et_input.getText().toString();

if (exp == null || exp.equals(" ")){

return;

}

if (!exp.contains(" ")){

return;

}

double result = 0;

String s1 = exp.substring(0,exp.indexOf(" "));

String op = exp.substring(exp.indexOf(" ")+1,exp.indexOf(" ")+2);

String s2 = exp.substring(exp.indexOf(" ")+3);

if(!s1.equals(" ")&&!s2.equals(" ")){

double d1 = Double.parseDouble(s1);

double d2 = Double.parseDouble(s2);

if(op.equals("+")){

result = d1+d2;

}else if(op.equals("-")){

result = d1-d2;

}else if(op.equals("×")){

result = d1*d2;

}else if(op.equals("÷")){

if(d2==0){

result = 0;

}else{

result = d1/d2;

}

}

if(!s1.contains(".")&&!s2.contains(".")){

int r = (int) result;

et_input.setText(r+"");

}else{

et_input.setText(result+"");

}

}else if(!s1.equals("")&&s2.equals("")){

et_input.setText(exp);

}else if(s1.equals("")&&!s2.equals("")){

double d2 = Double.parseDouble(s2);

if(op.equals("+")){

result = 0+d2;

}else if(op.equals("-")){

result = 0-d2;

}else if(op.equals("×")){

result = 0;

}else if(op.equals("÷")){

result = 0;

}

}

if(!s2.contains(".")){

int r = (int) result;

et_input.setText(r+"");

}else{

et_input.setText(result+"");

}else{

et_input.setText("");

}


}

}


andriod_2014
浏览 1867回答 2
2回答

andriod_2014

嗯,我是初学者,这段代码是我直接复制粘贴的,不好意思了。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Android