|
-
Aug 13th, 2009, 03:44 AM
#1
Thread Starter
Lively Member
find index number??
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
-
Aug 13th, 2009, 05:58 AM
#2
Re: find index number??
Here is how you can find the smallest number
Code:
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);
}
But I have no idea what the "index number" means
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Aug 13th, 2009, 06:23 AM
#3
Thread Starter
Lively Member
Re: find index number??
the index is the position number the number has in the array
-
Aug 13th, 2009, 06:31 AM
#4
Re: find index number??
Ok in this sample. i is the index of each item
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|