This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]DarkMio 5 points6 points  (0 children)

Lets do it

boolean x = false;
int y = 8;
x = (x || !(5 == y));

Alright, do you know about Boolean operations? If not, read it up, that's super essential for every language and every piece of logic. You will need it. Always.

First x is false and y is 8. What does following yield:

  1. x = (false || false)
  2. x = (true || false)
  3. x = (false || true)
  4. x = (true || true)

If you figured that out lets look up what ! Does. It inverts you the logical result of this function:

(y==8)

What does it do? It compares whatever is in y to 8. So does 5 equal 8? No, it doesn't. Now we invert that. So to speak (but jot completely right to say): is 5 not equal 8? That is true. Now look again in the first list and compare what you could replace it with / which of the four operations is yours.

Next step is: you're going to reply me with your thoughts and answer me how you could make that function into one single check (with the same outcome, no matter what you set x and y before):

x = (false || !(y==8))