Hello Nikolay,
Welcome to JavaRanch. As a small note, when posting code, it is much easier to read if you place it inside UBB [code] [/code] tags. And the easier it is to read the code, the easier it is for people to assist you
To learn more about UBB code tags, you can reference
this page. The [code] tag is discussed about 3/4 down the page.
You can fix the above post by clicking the edit button (the one with the pencil and paper), highlighting the code, then clicking the "code' button below the editing window. Then click the "Edit Post" button to submit the change.
To answer your question, since you are using it outside the loop, you have to initialize the
min variable outside the loop. There is a reason why you need to do this. Looking at the code you have right now, if someone were to run it and enter 0 for
n what would happen? Would anything inside the for loop run? And what happens when the line:
runs? If the code in the loop doesn't run, what is
min's value when it gets used in that line of code?
Think about those questions a bit and I think it will help you understand why you need to initialize the
min variable. See if that helps. Then post what you think you need to do to fix the issue and we can let you know if you are on the right track. If you still aren't seeing the solution, post what you think are the answers to these questions and we can help you get to the next step in solving the problem.
[ May 31, 2008: Message edited by: Mark Vedder ]