解九宫阵程序

来源:百度知道 编辑:UC知道 时间:2024/06/30 09:24:12
找关于能解九宫阵的程序.即9*9的格,分9组,每组3*3格,要求在每横每列填入1-9数字,不能重复.在每组也不能重复.
我想问一下,JAVA的代码用什么程序调用?
有了代码,但是不会生成程序来应用.

我用Java写的,尽管程序的可读性差一些,但可以实现九宫的问题

public class FoundNine {
public static boolean nq(int a, int b, int c) {
if ((a + b + c) == 15)
return true;
else
return false;
}

// 主方法
public static void main(String[] args) {
// 定义9个变量,作为九宫数
int a1, a2, a3, a4, a5, a6, a7, a8, a9;
int flag=0;
// 寻找九宫数循环
for (int a = 1; a <= 9; a++) {
a1 = a;
if(flag==1) break;
for (int b = 1; b <= 9; b++) {
if(flag==1) break;
if (b == a)
continue;
a2 = b;
for (int c = 1; c <= 9; c++) {
if (c == b || c == a)
continue;
a3 = c;
for (int d = 1;d<=9;d++) {
if ((d == c || d == b) || (d == a))
continue;
a4 = d;
for (int e = 1; e <= 9; e++) {
if ((e == d || e == c) || (e == b || e == a))
continue;
a5 = e;