一、结果图
二、源代码
package sy1;
import java.util.Scanner;
/**
* @author
*
*/
public class sy1_2 {
private static final Boolean ture = null;
static int k = 0;
static Boolean s[] = new Boolean[10];
static int a[] = new int[9];
static void dsf(int deep) {
if (deep == 0) {
if (a[0] + a[1] * 1.0 / a[2]
+ (a[3] * 100 + a[4] * 10 + a[5]) * 1.0 / (a[6] * 100 + a[7] * 10 + a[8]) == 10) {// 判断是否满足条件,满足则输出并计数器加一
System.out.println(a[0] + "\t" + a[1] + "\t" + a[2] + "\t" + a[3] + "\t" + a[4] + "\t" + a[5] + "\t"
+ a[6] + "\t" + a[7] + "\t" + a[8] + "\t");
k++;
}
}
for (int i = 1; i < 10; i++) {
if (s[i] == ture)// 数组初始值都为0
{
s[i] = false; // 确保后面的数不与当前值重复
a[9 - deep] = i;// a[]即A-I 的取值
dsf(deep - 1);// 递归到下一层
s[i] = ture;
}
}
}
public static void main(String[] args) {
dsf(9);
System.out.println("一共的解数" + k);
}
}