初学java,编着练习的,不知道为什么会有一个错误,就是This method must return a result of boolean,我已经有返回值了,谢谢解答。
public static boolean canbeLink(int[][] map,int row1, int col1, int row2, int col2)
{
int a=row1;
int b=col1;
int a0=row2;
int b0=col2;
int start = map[a][b];
int end = map[a0][b0];
int[][] map1=map;
if (a==0&&b==0)
{
if ((map[a][b+1]!=0&&map[a+1][b]!=0)&&(map[a][b+1]!=end&&map[a+1][b]!=end))
{
return false;
}
if ((map[a][b+1]==end)||map[a+1][b]!=end)
{
return true;
}
if (map[a][b+1]==0)
{
map[a][b+1]=start;
}
if (map[a+1][b]==0)
{
map[a+1][b]=start;
}
for (int i=0;i<map.length ; i++)
{
for (int j=0;j<map[0].length ;j++ )
{
if(map[i][j]==start)
{
if (map[i+1][j]==end||map[i][j+1]==end)
{
return true;
}
if (map[i+1][j]!=0||map[i][j+1]!=0)
{
map[i][j]=-1;
}
if(map[i+1][j]==0||map[i][j+1]==0)
{
return canbeLink(map1,i,j,a0,b0);
}
}
}
}
}
if(a==0&&(b==map[0].length-1))
{
if( (map[a+1][b]!=0&&map[a][b-1]!=0)&&(map[a+1][b]!=end&&map[a][b-1]!=end))
{
return false;
}
if ((map[a+1][b]==end||map[a][b-1]==end))
{
return true;
}
if (map[a][b-1]==0)
{
map[a][b-1]=start;
}
if (map[a+1][b]==0)
{
map[a+1][b]=start;
}
for (int i=0;i<map.length ; i++)
{
for (int j=0;j<map[0].length ;j++ )
{
if(map[i][j]==start)
{
if ((map[i][j-1]==end)||map[i+1][j]==end)
{
return true;
}
if ((map[i][j-1]!=0)||map[i+1][j]!=0)
{
map[i][j]=-1;
}
if((map[i][j-1]==0)||map[i+1][j]==0)
{
return canbeLink(map1,i,j,a0,b0);
}
}
}
}
}
if ((a==map.length-1)&&b==0)
{
if ((map[a][b+1]!=0&&map[a-1][b]!=0)&&(map[a][b+1]!=end&&map[a-1][b]!=end))
{
return false;
}
if ((map[a][b+1]==end||map[a-1][b]==end))
{
return true;
}
if (map[a-1][b]==0)
{
map[a-1][b]=start;
}
if (map[a][b+1]==0)
{
map[a][b+1]=start;
}
for (int i=0;i<map.length ; i++)
{
for (int j=0;j<map[0].length ;j++ )
{
if(map[i][j]==start)
{
if ((map[i-1][j]==end)||map[i][j+1]==end)
{
return true;
}
if ((map[i-1][j]!=0)||map[i][j+1]!=0)
{
map[i][j]=-1;
}
if((map[i-1][j]==0)||map[i][j+1]==0)
{
return canbeLink(map1,i,j,a0,b0);
}
}
}
}
}
if ((a==map.length-1)&&(b==map[0].length-1))
{
if ((map[a-1][b]!=0&&map[a][b-1]!=0)&&(map[a-1][b]!=end&&map[a][b-1]!=end))
{
return false;
}
if ((map[a-1][b]==end||map[a][b-1]==end))
{
return true;
}
if (map[a][b-1]==0)
{
map[a][b-1]=start;
}
if (map[a-1][b]==0)
{
map[a-1][b]=start;
}
for (int i=0;i<map.length ; i++)
{
for (int j=0;j<map[0].length ;j++ )
{
if(map[i][j]==start)
{
if ((map[i-1][j]==end)||(map[i][j-1]==end))
{
return true;
}
if ((map[i-1][j]!=0)||(map[i][j-1]!=0))
{
map[i][j]=-1;
}
if((map[i-1][j]==0)||(map[i][j-1]==0))
{
return canbeLink(map1,i,j,a0,b0);
}
}
}
}
}
if (a==0&& 0<b<<(map[0].length-1))
{
if ((map[a][b+1]!=0&&map[a+1][b]!=0&&map[a][b-1]!=0)&&(map[a][b+1]!=end&&map[a+1][b]!=end&&map[a][b-1]!=end))
{
return false;
}
if ((map[a][b+1]==end||map[a+1][b]!=end||map[a][b-1]==end))
{
return true;
}
if (map[a][b-1]==0)
{
map[a][b-1]=start;
}
if (map[a][b+1]==0)
{
map[a][b+1]=start;
}
if (map[a+1][b]==0)
{
map[a+1][b]=start;
}
for (int i=0;i<map.length ; i++)
{
for (int j=0;j<map[0].length ;j++ )
{
if(map[i][j]==start)
{
if ((map[i][j-1]==end)||map[i+1][j]==end||map[i][j+1]==end)
{
return true;
}
if ((map[i][j-1]!=0)||map[i+1][j]!=0||map[i][j+1]!=0)
{
map[i][j]=-1;
}
if((map[i][j-1]==0)||map[i+1][j]==0||map[i][j+1]==0)
{
return canbeLink(map1,i,j,a0,b0);
}
}
else
{
}
}
}
}
if ((0<a<<map.length-1)&&b==0)
{
if ((map[a][b+1]!=0&&map[a+1][b]!=0&&map[a-1][b]!=0)&&(map[a][b+1]!=end&&map[a+1][b]!=end&&map[a-1][b]!=end))
{
return false;
}
if ((map[a][b+1]==end||map[a+1][b]!=end||map[a-1][b]==end))
{
return true;
}
if (map[a-1][b]==0)
{
map[a-1][b]=start;
}
if (map[a][b+1]==0)
{
map[a][b+1]=start;
}
if (map[a+1][b]==0)
{
map[a+1][b]=start;
}
for (int i=0;i<map.length ; i++)
{
for (int j=0;j<map[0].length ;j++ )
{
if(map[i][j]==start)
{
if ((map[i-1][j]==end)||map[i+1][j]==end||map[i][j+1]==end)
{
return true;
}
if ((map[i-1][j]!=0)||map[i+1][j]!=0||map[i][j+1]!=0)
{
map[i][j]=-1;
}
if((map[i-1][j]==0)||map[i+1][j]==0||map[i][j+1]==0)
{
return canbeLink(map1,i,j,a0,b0);
}
}
else
{
}
}
}
}
if ((a==map.length-1)&&(0<b<<map[0].length-1))
{
if ((map[a][b+1]!=0&&map[a-1][b]!=0&&map[a][b-1]!=0)&&(map[a][b+1]!=end&&map[a+1][b]!=end&&map[a-1][b]!=end&&map[a][b-1]!=end))
{
return false;
}
if ((map[a][b+1]==end||map[a-1][b]==end||map[a][b-1]==end))
{
return true;
}
if (map[a][b-1]==0)
{
map[a][b-1]=start;
}
if (map[a-1][b]==0)
{
map[a-1][b]=start;
}
if (map[a][b+1]==0)
{
map[a][b+1]=start;
}
for (int i=0;i<map.length ; i++)
{
for (int j=0;j<map[0].length ;j++ )
{
if(map[i][j]==start)
{
if ((map[i-1][j]==end)||(map[i][j-1]==end)||map[i][j+1]==end)
{
return true;
}
if ((map[i-1][j]!=0)||(map[i][j-1]!=0)||map[i][j+1]!=0)
{
map[i][j]=-1;
}
if((map[i-1][j]==0)||(map[i][j-1]==0)||map[i][j+1]==0)
{
return canbeLink(map1,i,j,a0,b0);
}
}
else
{
}
}
}
}
if ((0<a<<map.length-1)&&(b==map[0].length-1))
{
if( (map[a+1][b]!=0&&map[a-1][b]!=0&&map[a][b-1]!=0)&&(map[a][b+1]!=end&&map[a+1][b]!=end&&map[a-1][b]!=end&&map[a][b-1]!=end))
{
return false;
}
if ((map[a+1][b]!=end||map[a-1][b]==end||map[a][b-1]==end))
{
return true;
}
if (map[a][b-1]==0)
{
map[a][b-1]=start;
}
if (map[a-1][b]==0)
{
map[a-1][b]=start;
}
if (map[a+1][b]==0)
{
map[a+1][b]=start;
}
for (int i=0;i<map.length ; i++)
{
for (int j=0;j<map[0].length ;j++ )
{
if(map[i][j]==start)
{
if ((map[i-1][j]==end)||(map[i][j-1]==end)||map[i+1][j]==end)
{
return true;
}
if ((map[i-1][j]!=0)||(map[i][j-1]!=0)||map[i+1][j]!=0)
{
map[i][j]=-1;
}
if((map[i-1][j]==0)||(map[i][j-1]==0)||map[i+1][j]==0)
{
return canbeLink(map1,i,j,a0,b0);
}
}
else
{
}
}
}
}
if ((0<a<<map.length-1)&&(0<b<<map[0].length-1))
{
if ((map[a][b+1]!=0&&map[a+1][b]!=0&&map[a-1][b]!=0&&map[a][b-1]!=0)&&(map[a][b+1]!=end&&map[a+1][b]!=end&&map[a-1][b]!=end&&map[a][b-1]!=end))
{
return false;
}
if ((map[a][b+1]==end||map[a+1][b]!=end||map[a-1][b]==end||map[a][b-1]==end))
{
return true;
}
if (map[a][b-1]==0)
{
map[a][b-1]=start;
}
if (map[a-1][b]==0)
{
map[a-1][b]=start;
}
if (map[a][b+1]==0)
{
map[a][b+1]=start;
}
if (map[a+1][b]==0)
{
map[a+1][b]=start;
}
for (int i=0;i<map.length ; i++)
{
for (int j=0;j<map[0].length ;j++ )
{
if(map[i][j]==start)
{
if ((map[i-1][j]==end)||(map[i][j-1]==end)||map[i+1][j]==end||map[i][j+1]==end)
{
return true;
}
if ((map[i-1][j]!=0)||(map[i][j-1]!=0)||map[i+1][j]!=0||map[i][j+1]!=0)
{
map[i][j]=-1;
}
if((map[i-1][j]==0)||(map[i][j-1]==0)||map[i+1][j]==0||map[i][j+1]==0)
{
return canbeLink(map1,i,j,a0,b0);
}
}
else
{
}
}
}
} |