四则运算

public  class   calc
{
public  String oper(float a,float b,char  c)
{
float  add=a+b;
float  jian=a-b;
float  chen=a*b;
float  chu=a/b;
switch(c)
{
case '+':
return  "想加的结果为:"+add;
case '-':
return  "想减的结果为:"+jian;
case '*':
return  "想乘的结果为:"+chen;
case '/':
return  "想除的结果为:"+chu;
default :
return  "出错了";
}
}
public  static  void  main(String  args[])
{
float a=100;
float  b=25;
calc c=new calc();
String result=c.oper(a,b,'/');
System.out.println(result);
}
}

posted on 2012-02-29 22:23  平安夜  阅读(105)  评论(0编辑  收藏  举报