046.
047.
The XOR operation is applied on these values.
The XOR
operator returns 0
when both values are the same, otherwise
returns 1.
Since both values are true, the XOR operator returns 0
which corresponds to false.
What will be output of the following code snippet? Explain
the reasons.
if(!(100 == 1000)) { //line 1
System.out.println(“TRUE gets printed”);
}
else {
System.out.println(“FALSE gets printed”);
}
Answer:
This code produces the following output:
TRUE gets printed
Line 1 checks the condition 100 == 1000, which is false. The if
statement checks the logical NOT(!) of this.
The Logical NOT
operator returns the opposite value of its operand. So,
it returns a
true. So, the if condition evaluates to
a true and the output above
is printed.
Explain the increment and decrement operators.
Answer:
The increment operator is represented by two plus signs. It
increments its operand. The following code demonstrates this:
int i = 10;