核心类
 1 package com.example.ddd;
 2 
 3 public class Core {
 4     int a;
 5     int b;
 6     int c;
 7     int d;
 8     public Core(int a,int b,int c,int d)
 9     {
10         this.a=a;
11         this.b=b;
12         this.c=c;
13         this.d=d;
14     }
15     public int calc()
16     {
17         if(c==0)
18         {
19             return a+b;
20         }
21         else if(c==1)
22         {
23             return a-b;
24         }
25         else if(c==2)
26         {
27             return a*b;
28         }
29         else if(c==3)
30         {
31             if(b==0)
32             {
33                 b++;
34             }
35             return a/b;
36         }
37         else
38         {
39             return jiecheng(d);
40         }
41     }
42     public String toString()
43     {
44         String A=new String();
45         String B=new String();
46         if(a<0)
47         {
48             A="("+a+")";
49         }
50         else
51         {
52             A=a+"";
53         }
54         if(b<0)
55         {
56             B="("+b+")";
57         }
58         else
59         {
60             B=b+"";
61         }
62         if(c==0)
63         {
64             return A+"+"+B;
65         }
66         else if(c==1)
67         {
68             return A+"-"+B;
69         }
70         else if(c==2)
71         {
72             return A+"*"+B;
73         }
74         else if(c==3)
75         {
76             return A+"/"+B;
77         }
78         else
79         {
80             return d+"!";
81         }
82     }
83 
84     public int jiecheng(int x)
85     {
86         if(x==0 || x==1)
87         {
88             return 1;
89         }
90         else
91         {
92             return x*jiecheng(x-1);
93         }
94     }
95 }
计算类

相关文章:

  • 2021-12-21
  • 2022-01-13
  • 2021-05-20
  • 2021-07-28
  • 2022-01-27
  • 2021-09-27
  • 2021-05-19
猜你喜欢
  • 2021-08-29
  • 2021-11-06
  • 2021-06-08
  • 2022-01-17
  • 2021-06-28
  • 2022-03-06
  • 2021-10-21
相关资源
相似解决方案