51,411
社区成员
发帖
与我相关
我的任务
分享
private double parseExcution(String line)
{
double result = 11.0;
String[] element = line.split(" ");
if(element.length != 2)
throw new IllegalArgumentException("Wrong input!");
String command = element[0];
System.out.println("command="+command);
try{
double value = Double.parseDouble(element[1]);
System.out.println("value="+value);
if(command == "sqrt"){
result = Math.sqrt(value);
}
else if(command == "log"){
result = Math.log(value);
}
else if(command == "sin"){
double deg2rad = Math.toRadians(value);
result = Math.sin(deg2rad);
}
else if(command == "cos"){
double deg2rad = Math.toRadians(value);
result = Math.cos(deg2rad);
}
else if(command == "tan"){
double deg2rad = Math.toRadians(value);
result = Math.tan(deg2rad);
}
else{
System.out.println("Invalid caculation!");
}
System.out.println("result="+result);
}
catch(Exception e){
throw new IllegalArgumentException("Invalid arguments!");
}
return result;
}