hi there if I have an array that looks like this
dataType[] arrayName = {3, 0, 5, 20, 8};
how can I find the smallest number in it??
and how can I return the index number of them all??
Im a beginner so go easy on me :)
thanks for helping
Printable View
hi there if I have an array that looks like this
dataType[] arrayName = {3, 0, 5, 20, 8};
how can I find the smallest number in it??
and how can I return the index number of them all??
Im a beginner so go easy on me :)
thanks for helping
Here is how you can find the smallest numberBut I have no idea what the "index number" meansCode:public static void main(String[] args)
{
final int[] array = { 3, 0, 5, 20, 8 };
// The easy way
java.util.Arrays.sort(array);
System.out.println("Min value = " + array[0]);
// The right way
int min = array[0];
for (int i = 1; i < array.length; i++)
if (array[i] < min)
min = array[i];
System.out.println("Min value = " + min);
}
the index is the position number the number has in the array:)
Ok in this sample. i is the index of each item