hello everyone, I am recieving this compiler error stating that

else if(input%100 || input%10 == rndNum%100 || rndNum%10)

this line ^

gives me the error

error: bad operand types for binary operator '||'

was hoping someone could explain this error to me if possible, also any advice would be greatly appreciated!

Thanks!!

Dani AI

Generated

The compiler message "bad operand types for binary operator '||' (first type: int, second type: boolean)" means one side of the logical OR is an int while the other side is a boolean. In Java, logical operators require boolean operands — an expression like input % 100 yields an int, not a boolean (unlike C where non-zero ints can act as true).

If the intent was to compare digit groups between input and rndNum (for example, match last two digits or last digit), each modulus result must be compared with == to produce booleans before combining with ||:

if ((input % 100 == rndNum % 100) || (input % 10 == rndNum % 10)) {
    // last-two or last-one digits match
}

If the intent was to test whether a remainder is nonzero (a divisibility-style test), explicitly compare with zero:

if ((input % 100 != 0) || (rndNum % 10 != 0)) {
    // at least one remainder is non-zero
}

As recommended, breaking complex expressions into named boolean variables improves clarity and debugging:

boolean lastTwoMatch = (input % 100) == (rndNum % 100);
boolean lastDigitMatch = (input % 10) == (rndNum % 10);
if (lastTwoMatch || lastDigitMatch) { ... }

Additional notes: precedence makes == evaluate before ||, but explicit parentheses aid readability. Avoid trying to use ints as booleans or mixing bitwise operators on ints with logical operators — single | with ints yields an int (not valid in an if), while || and && require boolean operands. Printing intermediate values or stepping through a debugger will quickly reveal which part is an int when this error appears.

Try to make use of parentheses inside the condition. Determine first the logic of the condition before using logical operators.

You may mean in that code:

input % 100 OR input % 10 is equal to rndNum % 100 OR rndNum % 10.

It can be restructured by using parentheses.

inputTwo == input % 10;

(input % 100) OR (inputTwo == rndNum % 100) OR (rndNum % 10)

Give it a try! :)

error: bad operand types for binary operator '||'
        else if((input%100) || (input%10 == rndNum%100) || (rndNum%10)){
                            ^
  first type:  int
  second type: boolean
1 error

lol sry im an idiot, this is what i get when i drink gin while programming lol, thanks for input tho!

Substitute input % 10 to inputTwo and try it again.

It's nothing dude. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.