报错: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
相关分类