Scanner in=new Scanner(System.in);
final int SIZE=3;
int [][]board=new int[SIZE][SIZE];
boolean gotresult=false;
int x=0;
int o=0;
//读入矩阵
for(int i=0;i<SIZE;i++)
{
for(int j=0;j<SIZE;j++)
{
board[i][j]=in.nextInt();
}
}
//判断行
for(int i=0;i<SIZE;i++)
{
x=0;
o=0;
for(int j=0;j<SIZE;j++)
{
if(board[i][j]==1)
{
x++;
}
else
{
o++;
}
}
if(x==SIZE||o==SIZE)
{
gotresult=true;
break;
}
}
//判断列
if(!gotresult)
{
for(int i=0;i<SIZE;i++)
{
x=0;
o=0;
for(int j=0;i<SIZE;i++)
{
if(board[j][i]==1)
{
x++;
}
else
{
o++;
}
}
if(x==SIZE||o==SIZE)
{
gotresult=true;
break;
}
}
}
//判断对角线
tic-tac-toe游戏(Java新手)
最新推荐文章于 2022-03-31 15:19:00 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)