Gennadiy Rabkin wrote:When I did it my code start to worked wrong and prints (0,0) pair, but initial code correct and works nice.
Michael's quite right. It'd be far better if you explained what you're trying to do (although I think I can guess). A couple of comment lines for each method would help as well, and it's a very good habit to get into.
However, a few pointers:
1. I'm surprised that your new code is printing anything at all, because the return statements at lines 22 and 31 look to me like they should cause a stack overflow because you've added an unconditional recursive call - and furthermore the one on line 22 has the parameters in a different order.
2. Returned values are generally meant to be used; on line 20 you don't.
3. Your compareNumbers() method changes two values but only returns one. Which one would that be? Hint: if you want to return two values, you should return an array (or an object that contains two values).
4. Try and avoid constructs like while(true). Essentially, it's an infinite loop, so it's a potential source of problems. Try replacing the true with a condition that causes the loop to end.
How I can return values? Is it possible in that case ?
Sure it is. You're just not doing it correctly. I suggest you read the tutorials.
Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Joined: Jul 11, 2012
Thanks everybody. Sorry that missed comments to parts of a code.
I have read tutorial. Deleted mad return statements and declare top, bottom and i as an instance variables: private static int i = 0, top = 0, bottom = 0;
And all works fine. You know this is an educational exercise. Main idea was to write a code of a program using top-bottom design practice and understand how methods communicate.