I need help with Computer Science! Can someone help?
!((x>y)||(y <= 0)) is equivalent to which of the following expressions? I !(x>y)|| !<=0) II !(x>y) &&! (y <=0) III(x<=y) && (y>0)
the ! symbol represents a 'flip'. ``` boolean a = !true; //this says a = (flip)true; so a = false; ``` Your question pertains to the logic of: ``` !((x>y)||(y <= 0)) ``` I'm sure you're already aware of less than / greater than / less than and equal to operators (operators perform operations on pieces of data.. + - * and / are examples of operators) the || operator translates to 'or'.. so within logic, doing: ``` int x = 5; int y = 7; if(y < x || x <= 5) { //this will execute if the statement in parenthesis is true } ``` In english, that if statement is if y is less than x OR if x is less than or equal to 5, then this statement is true. It happens that x is less than or equal to 5, so the entire statement is true. There is an && operator, also called an and operator. This is only true when both logic segments are true. ``` int x = 5; int y = 7; if(y < x && x <= 5) { //this will execute if the statement in parenthesis is true } ``` In this case, it isn't true, because both sides of the && would have to be true in order for the statement to be true. X would have to be greater than y and x would have to be less than or equal to 5. Back to your question - I'll write down the logic of what ``` !((x>y)||(y <= 0)) ``` says, and then you can write out the logic of the 3 answers. It's a good practice to write out the logic. Note that there are parenthesis around the entire logic statement.. remember that ! flips the outcome.. so whatever the outcome (true/false) of ``` (x > y) || (y <= 0) ``` is going to become the opposite when the ! is added outside of the parenthesis. I'm sure you're familiar with pemdas -- kind of the same thing here, whatever is in parenthesis will execute first. ``` !((x > y) || (y <= 0)) //outcome will be flipped ``` logic: (opposite of) (if x is greater than y OR y is less than or equal to 0).
ok I see, so it would only be the first problem?
I've provided the tools for you to figure out the answer to the question - now it's up to you to figure it out.
oh ok, thank you.
Sure
Join our real-time social learning platform and learn together with your friends!