+ 1
What is the Output and how explain?
public class Program { public static void main(String[] args) { int x=1 ,y=1, z=0; if(!(x++>1 && y++>1)) { z=x+y; } System.out.println(z); } }
2 Answers
+ 7
if(!(x++>1 && y++>1))
Here x++ its Post increment
*So first the x is compared to 1 i.e. x>1 is false
then x values is incremented So Now x=2.
*Since we are using && operator since one condition is false it will not check the other condition since it will be false anyways. So y=1.
*!() Not operator makes that condition true .
so the inside code gets executed
z=x+y;
z=2+1;
Output : 3
+ 5
3
x++>1 is false (1=1). x incremented afterwards and equals 2 then (afterwards, in any next lines, evaluations...)
Left part of && is false so right part is not evaluated (no need for it) and y is still equals 1. Condition of "if" is true (because !(false) so = true) and z is equal 2 + 1 so it's 3.



