Finding a Smallest Integer

Code :

public class MixerUpper{
public static void main(String[] args){
int[] myArray = new int[5];
printIntArray(myArray);
}
public static void printIntArray(int[] myParamVar)
{
int LOCATION = 0;
while(LOCATION<myParamVar.length)
{
System.out.print("In LOCATION " + LOCATION + " ");
System.out.print("Computer has written ");
LOCATION = LOCATION + 1;
System.out.println(( ( int) ( 4.9999 * Math.random() ) ) );
}
return;
}
}

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.

> run MixerUpper

In LOCATION 0 Computer has written 4

In LOCATION 1 Computer has written 0

In LOCATION 2 Computer has written 4

In LOCATION 3 Computer has written 0

In LOCATION 4 Computer has written 0

>

Now what I need to do is create code so that after it prints out this information. It prints out the smallest integer in the array by first printing its location and then the actual smallest number in the array.

I don't really know where to start on this one as I am very new to programming. Can anyone help out a little?

Re: Finding a Smallest Integer

How would you get the smallest number without the use of a computer?

Write that answer down into steps.

Then write code to perform those steps.

Ask more questions if you get stuck.

Re: Finding a Smallest Integer

Im getting no where with this. Can anyone start me out with a few lines of code giving me a hint?

Re: Finding a Smallest Integer

The best hint I have to give is, you don't need code. You need to understand the problem to be solved first. Then you need to come up with a plan to solve the problem. From this plan you can fine tune a series of steps to follow. From there you can write the code. If you get to the code writing part and still do not know what to do, post the steps you plan to take in solving the problem along with your question and someone will help you get back on track again.

Re: Finding a Smallest Integer

I dont get what you mean... I just want it to make another line under that would say in this case "Smallest Integer " " in LOCATION " " "

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: Finding a Smallest Integer

Quote:

I dont get what you mean...

What I mean is, you need to figure out how you will solve the problem. You need to print the "Smallest Integer", right?

How will you do that?

Easy. Print out the smallest integer. One step process. But this step can be broken down into more steps. So the steps to printing the smallest integer are given below.

Well to print the smallest integer you have to know which integer is the smallest.

You also have to be able to print.

Now that you know the smallest integer and know how to print, go ahead and print it out.

But wait. You don't know the smallest integer yet. There are more steps involved in knowing the smallest integer. We will get back to this in a minute.

Considering how to print, well that is something you know how to do in code with System.out.print so that does not need broken down into more steps.

Now back to the smallest integer. To get the smallest integer from a group of integers, you have to have a group of integers and some way to iterate through them, and some way to compare to see which is the smallest.

Take this as a hint for a starting point, and continue to break the steps down to the point you know how to write a line or two of code to accomplish each little task. Once you get through breaking the process down into little steps you can write code for, the results become an outline for the code. Refer to the process you design as you write the code to perform the steps.