public static ShuZi24 suanzhongjianleft24(int a,int b,int c,int d,int type){ ShuZi24 sz=null; try { String fh[] = {"+", "-", "*", "÷"}; for (int i = 0; i < 4; i++) { double sum1 = jiSuan(a, b, i); for (int j = 0; j < 4; j++) { double sum2 = jiSuan(c, sum1, j); for (int k = 0; k < 4; k++) { double sum = jiSuan( sum2, d, k); //sum=Math.ceil(sum); if (sum == 24) { //System.out.print( sum1+"=="+sum2+" "); num++; return sendMess(a,b,c,d,fh,i,j,k,type); // System.out.println("(" + c + "" + fh[j] + "(" + a + "" + fh[i] + "" + b + "))" + fh[k] + d+"="+sum); } } } } }catch(Exception e){ e.printStackTrace(); } return null; } public static ShuZi24 suanzhongjianright24(int a,int b,int c,int d,int type){ try { String fh[] = {"+", "-", "*", "÷"}; for (int i = 0; i < 4; i++) { double sum1 = jiSuan(a, b, i); for (int j = 0; j < 4; j++) { double sum2 = jiSuan( sum1,c, j); for (int k = 0; k < 4; k++) { double sum = jiSuan( d,sum2, k); //sum=Math.ceil(sum); if (sum == 24) { //System.out.print( sum1+"=="+sum2+" "); num++; return sendMess(a,b,c,d,fh,i,j,k,type); //System.out.println(d+fh[k]+"(("+a+fh[i]+b+")"+fh[j]+c+")"); } } } } }catch(Exception e){ e.printStackTrace(); } return null; } public static ShuZi24 suanLeft24(int a,int b,int c,int d,int type){ String fh [] ={"+","-","*","÷"}; double sum=0; for(int i=0;i<4;i++){ double sum1=jiSuan(a,b,i); for(int j=0;j<4;j++){ double sum2=jiSuan(sum1,c,j); for(int k=0;k<4;k++){ sum=jiSuan(sum2,d,k); //sum=Math.ceil(sum); if(sum==24){ num++; return sendMess(a,b,c,d,fh,i,j,k,type); // System.out.println("(("+a+fh[i]+b+")"+fh[j]+c+"))"+fh[k]+d); } } } } return null; } public static ShuZi24 suanRight24(int a,int b,int c,int d,int type){ String fh [] ={"+","-","*","÷"}; double sum=0; for(int i=0;i<4;i++){ double sum1=jiSuan(a,b,i); for(int j=0;j<4;j++){ double sum2=jiSuan(c,sum1,j); for(int k=0;k<4;k++){ sum=jiSuan(d,sum2,k); //sum=Math.ceil(sum); // System.out.println(d+fh[k]+"("+c+fh[j]+"("+a+fh[i]+b+"))="+Math.ceil(sum)); if(sum==24){ num++; // System.out.println(d+fh[k]+"("+c+fh[j]+"("+a+fh[i]+b+"))="+sum); return sendMess(a,b,c,d,fh,i,j,k,type); } } } } return null; } public static double jiSuan(double num1,double num2,int type){ double sum=0; if(type==0){ sum=num1+num2; }else if(type==1){ sum=num1-num2; }else if(type==2){ sum=num1*num2; }else{ if(num2==0){ return sum=0; } sum=num1/num2; } return sum; }
四个数24 四种公式计算 24结果
最新推荐文章于 2021-06-20 13:56:46 发布