Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
155 views
in Technique[技术] by (71.8m points)

java - How does one make sense of a string of logical comparisons?

For example, how would one make sense of (true && false || (53 < 24));? I'm aware that it evaluated to false I'm just curious as to how I would figure that out step by step. Thanks!

question from:https://stackoverflow.com/questions/65949111/how-does-one-make-sense-of-a-string-of-logical-comparisons

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You check a handy Java Operator Precedence table, which shows that && has higher precedence than ||, meaning that the expression is equivalent to:

((true && false) || (53 < 24))

Then you start evaluating:

((true && false) || (53 < 24))
        ↓
(     false      || (53 < 24))
                        ↓
(     false      ||   false  )
                 ↓
               false

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...