package javaapplication4;
public class JavaApplication4 {
public static void main(String[] args) {
int a[][]={
{5,3,4,6,7,8,9,1,2},
{6,7,2,1,9,5,3,4,8},
{1,9,8,3,4,2,5,6,7},
{8,5,9,7,6,1,4,2,3},
{4,2,6,8,5,3,7,9,1},
{7,1,3,9,2,4,8,5,6},
{9,6,1,5,3,7,2,8,4},
{2,8,7,4,1,9,6,3,5},
{3,4,5,2,8,6,1,7,9}};
int i,j,k,m,z,n;
//
对行进行判断
for(i=0;i<9;i++)
{for(j=0,k=1,z=0;j<9;j++,k++)
{for(m=0;m<9;m++)
if(a[i][m]==k) {z++;break;}
}
if(z!=9) {n=i+1;System.out.println("
第
"+n+"
行错误
");System.exit(-1);}
}
//
对列进行判断
for(i=0;i<9;i++)
{for(j=0,k=1,z=0;j<9;j++,k++)
{for(m=0;m<9;m++)
if(a[m][i]==k) {z++;break;}
}
if(z!=9) {n=i+1;System.out.println("
第
"+n+"
列错误
");System.exit(-1);}
}
//
对小方块进行判断
for(k=0;k<=6;k+=3)
{for(n=0;n<=6;n+=3)
{for(m=1,z=0;m<=9;m++)
{for(i=k;i<=(k+2);i++)
{for(j=n;j<=(n+2);j++)
{if(a[i][j]==m) {z++;break;}
}
if(z==m) break;
}}
if(z!=9) {System.out.println("ERROR");System.exit(-1);}
}
}
System.out.println("
正确
");
}
}