简体   繁体   English

如何修复错误“二元运算符 '>=' 第一种类型的错误操作数类型:int[] 第二种类型 int”

[英]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.

相关问题 获取二元运算符&#39;&gt;&#39;的错误错误操作数类型第一种类型:double []第二种类型:int - Getting error bad operand types for binary operator '>' first type: double [] second type: int 二元运算符&#39;|的操作数类型错误 |” 第一种类型:int; 第二种类型:int。 这是什么意思? - Bad operand types for binary operator '| |' first type: int; second type: int. What does this mean? 二元运算符“&amp;”的错误操作数类型第一种类型:int[] 第二种类型:int - Bad operand types for binary operator ‘&’ First type: int[] Second type: int 二元运算符“!=”的错误操作数类型 第一个类型 int[] 第二个类型 int - Bad operand types for binary operator “!=” first type int[] second type int 二进制运算符“-”的错误操作数类型第一类型:int; 第二种类型:java.lang.String - bad operand types for binary operator “-” first type: int; second type: java.lang.String 二进制运算符&#39;/&#39;的错误操作数类型第一类型字符串第二类型int - Bad Operand types for binary operator '/' first type String second type int 二进制运算符&#39;!=&#39;的错误操作数类型第一类型:字符串第二类型:int - bad operand types for binary operator '!=' first type: String second type: int 为什么我会收到此错误? “二元运算符“&amp;&amp;”的操作数类型错误 第一种类型:int 第二种类型:布尔值 - Why am I getting this error? "Bad operand type for binary operator "&&" first type: int second type: boolean" 二进制运算符“ *”的错误操作数类型如何将类型转换为int - bad operand types for binary operator '*' how to covert the type to int 二进制运算符的错误操作数类型+第一类型int []和第二类型int - Bad operand type for binary operator + first type int[] and second type int
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM