java, simplify this code
Simplify this code to some other code which behaves the same way (your answer should not have an else in it): ``` if (x==5) { if (!(x==5)) { x=x+1; } } else x=x+1;
if(x!=5) x++; the inner if is equivalent to the else, therefore if the statement is true nothing will happen and the only action is taken when x!=5
I thought that the inner if wasn't doing anything at all, I mean yes, its equivalent to the else but there is no way it would get executed in the first place because of he condition on the outer if
correct, it essentially reads if(yes) if(no) x++; else x++;
* put brackets around that first if() in above comment, stupid mistake I always make and always spend an hour debugging
Lol, thankyou
Join our real-time social learning platform and learn together with your friends!