Friday, August 19, 2011

Can someone explain this java program?

thats the portion that actually reverses the number. say you put in the number 321 into that portion of the code as 'n'. (321 != 0) = true, ret = ret * 10 + ( 321 % 10) = 1. (ret was not initialized, so it defaults to 0). n then goes to 32, 32 still does not = 0, so 1 * 10 + (32%10) = 12, n then = 3, run it one more time to get 123. hope that helps

No comments:

Post a Comment