Emily Blackwood
Emily Blackwood

Reputation: 1

Bad operand types for binary operator "<"

Getting a bad operand types for binary operator ">",

first type: boolean; second type: int.

In this line:

if( 0 < r < getNumberOfRows()&& 0 < c < getNumberOfColumns());

The getNumberOfRows() returns an int value, and r is declared as an int right above the if statement. No idea what is wrong.

public int numberAdjacent(int row, int column)
{
    int count = 0;
    int r = row;
    int c = column;        

    if( 0 < r < getNumberOfRows()&& 0 < c < getNumberOfColumns()){
        if(map[r+1][c+1]) {
            count++;
        }

Upvotes: 0

Views: 326

Answers (1)

Joachim Isaksson
Joachim Isaksson

Reputation: 181077

Java does not have a a < b < c construct to check if b is between a and c. Instead, you need to break it into two separate comparisons, a < b and b < c.

In your example it would look like;

if( 0 < r && r < getNumberOfRows() && 0 < c && c < getNumberOfColumns() ) {

Upvotes: 1

Related Questions