答案:
/*我编的小程序,逻辑有点混乱,注释也少得可怜,但应该能列出任何能用四则运算得出24的四个1~10的数的等于24的等式。
大家若有空,请指点。*/
public class Test24Point{
public static void main(String[] args){
int index = 0 ;
int temp = 0 ;
int totalSuc = 0 ;
int numb[] = new int[4];//the first four numbers
double num[][] = new double[36][3];//three numbers after calculating
double total[] = new double[6];//the number after three steps of calculating
double p[][] = new double[6][8];
double q[][] = new double[3][7];
//System.out.println(2465%108);
//System.out.println(2465/108);
System.out.println("\"a--b\"means\"b-a\"");
System.out.println("\"a//b\"means\"b/a\"\n");
/* for(int h = 0; h <= 9; h ++)//Get the first four numbers for calculating and store into the array numb[4];.
for(int i = 0; i <= 9; i ++)
for(int j = 0; j <= 9; j ++)
for(int k = 0; k <= 9; k ++){
numb[0] = h ;
numb[1] = i ;
numb[2] = j ;
numb[3] = k ;
}*/
for(int i = 0 ; i < 4 ; i ++){
numb[i] = Integer.parseInt(args[i]);
}
for(int i = 0; i < 3; i ++)//Get two of the four to calculate and then store the new number into the array p;
for(int j = i + 1; j < 4 ; j ++,temp ++){
p[temp][0] = numb[i] + numb[j];
p[temp][1] = numb[i] - numb[j];
p[temp][2] = numb[j] - numb[i];
p[temp][3] = numb[i] * numb[j];
if(numb[j] != 0)
p[temp][4] = numb[i] / (double)numb[j];
else
p[temp][4] = 10000;
if(numb[i] != 0)
p[temp][5] = numb[j] / (double)numb[i];
else
p[temp][5] = 10000;
switch(temp){
case 0:p[temp][6] = numb[2]; p[temp][7] = numb[3];break;
case 1:p[temp][6] = numb[1]; p[temp][7] = numb[3];break;
case 2:p[temp][6] = numb[1]; p[temp][7] = numb[2];break;
case 3:p[temp][6] = numb[0]; p[temp][7] = numb[3];break;
case 4:p[temp][6] = numb[0]; p[temp][7] = numb[2];break;
case 5:p[temp][6] = numb[0]; p[temp][7] = numb[1];
}
}
for(int k = 0,tem = 0; k < 6; k ++)//Get the possible three numbers and store into the array num[36][3] for calculating .
for(int l = 0; l < 6; l ++,tem ++){
num[tem][0] = p[k][l] ;
num[tem][1] = p[k][6] ;
num[tem][2] = p[k][7] ;
for(int t = 2,m = 0, n = 0,te = 0; t >= 0; t --,te ++){//Get two of the three to calculate and then store the new number into the array q;
m = (t + 1)%3;
n = (t + 2)%3;
q[te][6] = num[tem][t];
q[te][0] = num[tem][m] + num[tem][n];
q[te][1] = num[tem][m] - num[tem][n];
q[te][2] = num[tem][n] - num[tem][m];
q[te][3] = num[tem][m] * num[tem][n];
if(num[tem][n] != 0)
q[te][4] = num[tem][m] / (double)num[tem][n];
else
q[te][4] = 10000 ;
if(num[tem][m] != 0)
q[te][5] = num[tem][n] / (doub
上一个:轻松实现Java 用户界面编程
下一个:学习小记Java的反射机制