[英]How to fix the error "Bad Operand Types for Binary Operator '>=' first type: int[] second type int"
**The error is with this line: ** **错误在于这一行:**
if ((board[r + vertical[movenumber]]) <= 8 && board[r + vertical[movenumber]] >= 1)
**Whole method if needed: ** **如果需要,整个方法:**
public void tour()
{
int starter = 1;
int start1 = (int)(Math.random() * 8 - 1) + 1;
int start2 = (int)(Math.random() * 8 - 1) + 1;
board[start1][start2] = starter;
int r = start1;
int c = start2;
for (int count = 0; count < board[row].length; count++)
{
numb[count] = count;
}
for (int runs = 2; runs <= 64; runs++)
{
int movenumber = (int)(Math.random() * 8 - 1) + 1;
if ((board[r + vertical[movenumber]]) <= 8 && board[r + vertical[movenumber]] >= 1)
{
if (board[r + vertical[movenumber]][c + horizontal[movenumber]] == 0)
{
board[r + vertical[movenumber]][c + horizontal[movenumber]] = runs;
// System.out.println(r + "," + c);
r = r + vertical[movenumber];
c = c + horizontal[movenumber];
}
}
}
}
The error is pretty specific - you are trying to compare an array with an int
.该错误非常具体 - 您正在尝试将数组与
int
进行比较。 The board[r + vertical[movenumber]]
expression is an array (or int[]
, specifically), because your board is int[][]
.所述
board[r + vertical[movenumber]]
表达是一个数组(或int[]
具体而言),因为你的板是int[][]
To make it an int
, you need to add a second index, just like you do in the following lines: board[r + vertical[movenumber]][c + horizontal[movenumber]]
.要使其成为
int
,您需要添加第二个索引,就像您在以下几行中所做的那样: board[r + vertical[movenumber]][c + horizontal[movenumber]]
。
And from quick glance at the code, I think it should be r + vertical[movenumber] <= 8
instead.快速浏览一下代码,我认为它应该是
r + vertical[movenumber] <= 8
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.