帖代码
static String[] symbolArr = new String[]{"+","-","*","/"};
static int sumNumber =0;
static int[] valueNumbers =new int[]{1,2,3,4};
public static void main(String[] args) {
for (int i = 0; i < symbolArr.length ; i++) {
for (int j = 0; j < symbolArr.length ; j++) {
for (int k = 0; k < symbolArr.length; k++) {
sumNumber=getValue(valueNumbers,new String[]{symbolArr[i], symbolArr[j], symbolArr[k]});
if (sumNumber<=16){
System.out.print(sumNumber);
}
}
}
}
}
static int getValue(int[] values, String[] args){
for (int i = 0; i < args.length; i++) {
switch (args[i]){
case "+":
switch (i){
case 0:
sumNumber =values[0]+values[1];
break;
case 1:
sumNumber = sumNumber+values[2];
break;
case 2:
sumNumber = sumNumber+values[3];
break;
}
break;
case "-":
switch (i){
case 0:
sumNumber =values[0]-values[1];
break;
case 1:
sumNumber = sumNumber-values[2];
break;
case 2:
sumNumber = sumNumber-values[3];
break;
}
break;
case "*":
switch (i){
case 0:
sumNumber =values[0]*values[1];
break;
case 1:
sumNumber = sumNumber*values[2];
break;
case 2:
sumNumber = sumNumber*values[3];
break;
}
break;
case "/":
switch (i){
case 0:
sumNumber =values[0]/values[1];
break;
case 1:
sumNumber = sumNumber/values[2];
break;
case 2:
sumNumber = sumNumber/values[3];
break;
}
break;
}
}
return sumNumber;
} |