Boolean Operators: Precedence


#1

https://www.codecademy.com/courses/learn-java/lessons/conditionals-control-flow/exercises/boolean-operators-precedence?action=lesson_resume&link_content_target=interstitial_undefined

For the precedence lesson, i got the correct answer. I’m not too sure why i got the correct answer too. Shouldn’t my reading be true instead? However, I’m a little confused as to the precedence part. If ! is read first, followed by && then ||. Doesn’t that mean only the reading of || matter since its the last one to be read?


public class Precedence {
	public static void main(String[] args) {

		boolean riddle = !( 1 < 8 && (5 > 2 || 3 < 5));
		System.out.println(riddle);

	}
}


#2

this is true, except anything in parentheses is evaluated first, even before !

so, given the or operator is between parentheses means it evaluates first.


#3

Oh I see. That was pretty simple. Haha. Thanks!


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.