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 }
相关文章: