开发者

does equality operator return a boolean value

even = number % 2开发者_如何转开发 == 0;

This is a valid java assignment which was given in a website as example.

So does equality operator return a boolean value after evaluation ?

Like in this case, number % 2 == 0 , if true, it assigns even = true?


Yes. Comparison operators evaluate to boolean values.


Yes. From the Java Language Specification, section 15.21:

The equality operators are syntactically left-associative (they group left-to-right), but this fact is essentially never useful; for example, a==b==c parses as (a==b)==c. The result type of a==b is always boolean, and c must therefore be of type boolean or a compile-time error occurs. Thus, a==b==c does not test to see whether a, b, and c are all equal.

(Emphasis mine - the rest of the paragraph is somewhat irrelevant, but it's the context in which the important phrase appears.)


Yes, comparisons made with boolean operators evaluate to a boolean value

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜