Results 1 to 4 of 4

Thread: find index number??

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Posts
    87

    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

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    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

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Posts
    87

    Re: find index number??

    the index is the position number the number has in the array

  4. #4
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    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
  •  



Click Here to Expand Forum to Full Width