麻烦帮我看看以下java代码哪里错了?
public class ArrayList {
static int X=8;
static int Y=8;
static int[][] chess=new int[X][Y];
static int a,b;
public static void main(String[] args){
for(int i=0;i<X;i++){
for(int j=0;j<Y;j++){
chess[i][j]=0;
}
}
if(TravelChessBoard(2,0,1)==1){
for(int i=0;i<X;i++){
for(int j=0;j<Y;j++){
System.out.print(chess[i][j]+"\t");
}
System.out.println();
}
}
}
public static int nextxy(int x,int y,int count){
switch(count){
case 0:
if(x+2<=X-1&&y-1>=0&&chess[x+2][y-1]==0){
a=x+2;
b=y-1;
return 1;
}
break;
case 1:
if(x+2<=X-1&&y+1<=Y-1&&chess[x+2][y+1]==0){
a=x+2;
b=y+1;
return 1;
}
break;
case 2:
if(x+1<=X-1&&y-2>=0&&chess[x+1][y-2]==0){
a=x+1;
b=y-2;
return 1;
}
break;
case 3:
if(x+1<=X-1&&y+2<=Y-1&&chess[x+1][y+2]==0){
a=x+1;
b=y+2;
return 1;
}
break;
case 4:
if(x-2>=0&&y-1>=0&&chess[x-2][y-1]==0){
a=x-2;
b=y-1;
return 1;
}
break;
case 5:
if(x-2>=0&&y+1<=Y-1&&chess[x-2][y+1]==0){
a=x-2;
b=y+1;
return 1;
}
break;
case 6:
if(x-1>=0&&y-2>=0&&chess[x-1][y-2]==0){
a=x-1;
b=y-2;
return 1;
}
break;
case 7:
if(x-1>=0&&y+2<=Y-1&&chess[x-1][y+2]==0){
a=x-1;
b=y+2;
return 1;
}
break;
default :
break;
}
return 0;
}
public static int TravelChessBoard(int x,int y,int tag){
int flag=0,count=0;
chess[x][y]=tag;
if(tag==X*Y){
return 1;
}
flag=nextxy(x,y,count);
while(flag==0&&count<7){
count=count+1;
flag=nextxy(x,y,count);
}
while(flag==1){
if(TravelChessBoard(a,b,tag+1)==1){
return 1;
}
count=count+1;
flag=nextxy(x,y,count);
while(flag==0&&count<7){
count=count+1;
flag=nextxy(x,y,count);
}
if(flag==0){
chess[x][y]=0;
}
}
return 1;
}
}
输出结果:
0 0 39 44 0 0 0 0
40 43 0 0 0 47 0 0
1 34 41 38 45 0 31 48
42 15 36 0 32 29 46 0
35 2 33 16 37 24 49 30
14 5 12 9 22 19 28 25
3 10 7 20 17 26 23 50
6 13 4 11 8 21 18 27
是国际象棋中的马踏棋盘问题,即马要踏遍每一个空格