Solution Review: Compute an Expression Using Logic
In this review, the solution of the challenge 'Compute an expression using logic' from the previous lesson is provided.
We'll cover the following...
We'll cover the following...
Solution: Is it true or false?
Press + to interact
Java
class HelloWorld {public static void main( String args[] ) {boolean x = true;boolean y = true;boolean answer;boolean not_x = !x;boolean xor_x = not_x ^ x;boolean and_xy = xor_x && y;answer = !and_xy;System.out.println(answer);}}
Understanding the code
Line 7
- The variable,
not_x
stores the result of the Boolean NOT of x. - The value of
x