[英]basic if statement, operator <= undefined
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
对于参数类型
boolean
, int
,运算符<=
未定义
Please help me fix it. 请帮我修理一下。
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
. 得到错误的原因是
6 <= N
的第一个条件解析为boolean
,然后尝试检查boolean
是否<=
到int
。 That does not compute. 这不算。
您无法在一次检查中比较2个条件,您需要将其拆分为两个检查
if (N % 2 == 0 && N >= 6 && N <= 20)
您应该使用逻辑运算符(在这种情况下为&&)分隔条件:
if (N % 2 == 0 && N>=6 && N <= 20)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.