Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

basic if statement, operator <= undefined

Tags:

java

I'm new to programming

if( (N%2==0) && (6<=N<=20) ) 

Throws the error below

The operator <= is undefined for the argument type(s) boolean, int
Please help me fix it.

like image 451
sanashariff Avatar asked Mar 14 '23 12:03

sanashariff


1 Answers

You can't compound the statement like that. You need to && it.

For example,

if ((N % 2 == 0) && (6 <= N && N <= 20)) {...} 

The reason you get the error is the first condition of 6 <= N resolves to a boolean and you then attempt to check if a boolean is <= to an int. That does not compute.

like image 61
ChiefTwoPencils Avatar answered Mar 17 '23 13:03

ChiefTwoPencils