Ask your own question, for FREE!
Computer Science 33 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!
Latest Questions
kaelynw: who should I draw (anime characters)
51 minutes ago 8 Replies 2 Medals
kaelynw: should I post my art?
2 hours ago 11 Replies 3 Medals
danielfootball123: Question.... How much is questioncove worth if I were to buy it?
6 hours ago 5 Replies 0 Medals
HeyItsAlicia: Mits midnight!!! Happy 16th bday to me !!
3 hours ago 39 Replies 8 Medals
XShawtyX: Art
1 hour ago 2 Replies 1 Medal
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!