OpenStudy (javk):

java, simplify this code

2 years ago
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;

2 years ago
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

2 years ago
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

2 years ago
OpenStudy (caominhim):

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

2 years ago
OpenStudy (caominhim):

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

2 years ago
OpenStudy (javk):

Lol, thankyou

2 years ago
Similar Questions: