Re: Smallest Integer Finder
Quote:
Originally Posted by
antnas
What this code does is print out an array of 5 integers with locations and different numbers in the locations. For example when I ran it this is what is printed out.
No it doesn't.
It prints out 5 random numbers.
It never actually puts them in the array.
As for your problem, you'll need to store the lowest number found so far, and check it on each iteration. You'll also need to store the value of LOCATION when it was found.
Re: Smallest Integer Finder
I want to set up code that would be like System.out.println("Smallest integer " //code here to print out smallest integer(no clue here) "in location " //code to find location of that smallest integer here.
Is this even the right aproach?
Re: Smallest Integer Finder
You have 2 issues. First finding the smallest value which has been explained by Tolls above. Second displaying the result which would need a print statement similar to what you post above. So what is your problem? Post your code, error messages and ask a specific question.
Re: Smallest Integer Finder
Quote:
Originally Posted by
antnas
I want to set up code that would be like System.out.println("Smallest integer " //code here to print out smallest integer(no clue here) "in location " //code to find location of that smallest integer here.
Is this even the right aproach?
Step number 1 is getting your code to actually set the value of each element in the array. Once you've done that you could actually keep track of what the lowest integer is while you're building your array, rather than doing another loop through in the end. With a few minor tweaks you should have this thing buttoned up.
Re: Smallest Integer Finder
Since you want to access this array from multiple (static) methods, consider making it a (static) class variable. Then have methods that do specific things with it: fillArray(), printArray(), printMinimum(), etc.