Ask your own question, for FREE!
Computer Science 30 Online
OpenStudy (javk):

java, simplify this code

OpenStudy (javk):

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;

OpenStudy (caominhim):

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

OpenStudy (javk):

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

OpenStudy (caominhim):

correct, it essentially reads if(yes) if(no) x++; else x++;

OpenStudy (caominhim):

* put brackets around that first if() in above comment, stupid mistake I always make and always spend an hour debugging

OpenStudy (javk):

Lol, thankyou

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!