package src;
import java.io.*;
public class Calculation {
public static void main(String args[]) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str=br.readLine();
String oper1="",oper2="";
char c,operation='0';
int operationPosition=0;
double operand1,operand2,result=0;
count:
for(int i=1;i<str.length();i++){
c=str.charAt(i);
switch(c){
case '+':
operation='+';
operationPosition=i;
break count;
case '-':
operation='-';
operationPosition=i;
break count;
case '*':
operation='*';
operationPosition=i;
break count;
case '/':
operation='/';
operationPosition=i;
break count;
}
}
oper1=str.substring(0,operationPosition);
oper2=str.substring(operationPosition+1,str.length());
operand1=Double.parseDouble(oper1);
operand2=Double.parseDouble(oper2);
switch(operation){
case'+':
result=operand1+operand2;
break;
case'-':
result=operand1-operand2;
break;
case'*':
result=operand1*operand2;
break;
case'/':
if(operand2==0) System.out.println("Denominator can't be zero.");
else result=operand1/operand2;
break;
}
System.out.println(result);
}
}
大家看看还有改进的地方吗?