日期:2014-05-20  浏览次数:20835 次

请教一下
package   calc;

public   class   Server   {

public   static   double   Getresult(double   numberA,double   numberB,String   mark){

double   result=0d;
 
switch   (mark){
case   "+ ":   result=numberA+numberB;break;
case   "- ":   result=numberA-numberB;break;
case   "* ":   result=numberA*numberB;break;
case   "/ ":   result=numberA/numberB;break;

}
 

return   result;


}

}
请问一下、这个哪边有错么?

------解决方案--------------------
public class Server { 

public static double Getresult(double numberA,double numberB){ 

double result=0d; 
char mark='+'; //最好设置个初始值,或者用System.in手动输入符号
switch(mark){ 
case '+': result=numberA+numberB;break; 
case '-': result=numberA-numberB;break; 
case '*': result=numberA*numberB;break; 
case '/': result=numberA/numberB;break; 


  

return result; 



public static void main(String args[]){
double m=Getresult(3.0,4.0);
System.out.print(m);
}

}