欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

java简单的计算器类,进行两个数的加减乘除运算

程序员文章站 2022-06-24 22:26:38
...

```java
import.java.util.Scanner;
class jisuanqi
{
  double add(double a,double b)
  {return (a+b);}
   double jian(double a,double b)
  {return (a-b);}
  double cheng(double a,double b)
  {return (a*b);}
  double chu(double a,double b)
  {return (a/b)}
}
public class jisuan{
public static void main(String arag[])
{
  jisuanqi js=new jisuanqi(a,b);
  Scanner in=Scanner(System.in);
  System.out,print("请输入第一个数据:");
  Double a=in.nextDouble();
  System.out.print("请输入第二个数据:");
  Double b=in.nextDouble();
  System.out.print("请输入运算符号 +  -  *  / :");   
  char s=in.next().charAt(0);
  int result;
  switch(s)
  {
  case '+':
  System.out.println(js.add(a,b)); break;
  case '-':
  System.out.println(js.jian(a,b));break;
  case '*':
  System.out.println(js.cheng(a,b));break;
  case '/':
  System.out.println(js.chu(a,b));break;
  }
}
}