import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class 神奇算式 {
static int sum = 0;
static List<String> list = new ArrayList<String>();
private static int a;
private static int b;
private static int c;
private static int d;
private static int sum2 = 0;
private static int sum1 = 0;
public static void main(String[] args) {
for (int i = 1; i < 10; i++) {
go(i + "");
}
System.out.println(list);
System.out.println(list.size());
// 遍历每个字符串
Iterator<String> iterator = list.iterator();
while (iterator.hasNext()) {
String s = iterator.next();
check(s);
}
sum = sum1 + sum2 / 2;
System.out.println("共有: " + sum);
}
private static void check(String s) {
char[] array = s.toCharArray();
int[] x = new int[array.length];
for (int i = 0; i < x.length; i++) {
a = Integer.parseInt(String.valueOf(array[i]));
for (int j = 0; j < x.length; j++) {
b = Integer.parseInt(String.valueOf(array[j]));
for (int k = 0; k < x.length; k++) {
c = Integer.parseInt(String.valueOf(array[k]));
for (int l = 0; l < x.length; l++) {
d = Integer.parseInt(String.valueOf(array[l]));
// 判断
if (a != b && a != c && a != d && b != c && b != d
&& d != c) {
if (a * Integer.parseInt(b + "" + c + d) == Integer
.parseInt(s)) {
sum1++;
System.out.println(a + "*" + b + "" + c + d
+ "=" + s);
}
if (Integer.parseInt(a + "" + b)
* Integer.parseInt("" + c + d) == Integer
.parseInt(s)) {
System.out.println(a + "" + b + "*" + c + ""
+ d + "=" + s);
sum2++;
}
}
}
}
}
}
}
private static void go(String s) {
if (s.length() == 4) {
list.add(s);
return;
}
if (s.length() > 4) {
return;
}
for (int i = 0; i < 10; i++) {
String y = s + i;
go(y);
}
}
}
import java.util.Iterator;
import java.util.List;
public class 神奇算式 {
static int sum = 0;
static List<String> list = new ArrayList<String>();
private static int a;
private static int b;
private static int c;
private static int d;
private static int sum2 = 0;
private static int sum1 = 0;
public static void main(String[] args) {
for (int i = 1; i < 10; i++) {
go(i + "");
}
System.out.println(list);
System.out.println(list.size());
// 遍历每个字符串
Iterator<String> iterator = list.iterator();
while (iterator.hasNext()) {
String s = iterator.next();
check(s);
}
sum = sum1 + sum2 / 2;
System.out.println("共有: " + sum);
}
private static void check(String s) {
char[] array = s.toCharArray();
int[] x = new int[array.length];
for (int i = 0; i < x.length; i++) {
a = Integer.parseInt(String.valueOf(array[i]));
for (int j = 0; j < x.length; j++) {
b = Integer.parseInt(String.valueOf(array[j]));
for (int k = 0; k < x.length; k++) {
c = Integer.parseInt(String.valueOf(array[k]));
for (int l = 0; l < x.length; l++) {
d = Integer.parseInt(String.valueOf(array[l]));
// 判断
if (a != b && a != c && a != d && b != c && b != d
&& d != c) {
if (a * Integer.parseInt(b + "" + c + d) == Integer
.parseInt(s)) {
sum1++;
System.out.println(a + "*" + b + "" + c + d
+ "=" + s);
}
if (Integer.parseInt(a + "" + b)
* Integer.parseInt("" + c + d) == Integer
.parseInt(s)) {
System.out.println(a + "" + b + "*" + c + ""
+ d + "=" + s);
sum2++;
}
}
}
}
}
}
}
private static void go(String s) {
if (s.length() == 4) {
list.add(s);
return;
}
if (s.length() > 4) {
return;
}
for (int i = 0; i < 10; i++) {
String y = s + i;
go(y);
}
}
}