FAQs on the exercise Combining Conditional Operators
There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
You can also find further discussion and get answers to your questions over in #get-help.
Agree with a comment or answer? Like () to up-vote the contribution!
Never mind, I just got it. I was too busy getting scared off by the math aspect that I forgot to evaluate the statements for what they actually were solving if they are true or false. Followed the order, reminded myself of what && and || actually entails and voila!
Exercise Instructions: Using your understanding of the order of execution, find out whether the value of each expression is true or false .
When you’re ready, uncomment the print statements to find out if you are right.
I am getting stuck here. I have run both sides and the left evaluates to true and the right evaluates to false.true && false evaluates to false but ex1 prints true. what am I missing?
[codebyte]
public class Operators {
public static void main(String args) {
int a = 6;
int b = 3;
boolean ex1 = !(a == 7 && (b >= a || a != a));
// !(a == 7); evaluates true
//b >= a || a != a; evaluates false
System.out.println(ex1);
Thanks, I sent it to a friend because I couldn’t wait days for a reply! That is the one frustrating thing about codecademy projects. Appreciate you took the time. I hope it helps someone ~
int a = 6;
int b = 3;
boolean ex2 = a == b || !(b > 3);
boolean ex3 = !(b <= a && b != a + b);
// ex2
a == b || !(b > 3)
// Parenthesis has higher precedence.
a == b || !(3 > 3)
a == b || !(false)
a == b || true
// Equality == has higher precedence than logical OR ||
// See the operator precedence table in link.
6 == 3 || true
false || true
true
// ex3
!(b <= a && b != a + b)
// Parentheses has higher precedence.
// Of the operators inside the parentheses, + has the highest precedence
!(b <= a && b != 6 + 3)
!(b <= a && b != 9)
// <= has higher precedence than && and !=
!(3 <= 6 && b != 9)
!(true && b != 9)
// != has higher precedence than &&
!(true && 3 != 9)
!(true && true)
!(true)
false