- Initialize a variable M to Integer.MIN_VALUE - Compare each element in the array to M - If the element is smaller than M, set M equal to that element's value.
When you get to the end of the array, M is the minimum value in the array. If you want the index of the minimum value, then just keep a second variable to hold the index, and set it each time you set M.
don't you still need to check for 0 length arrays? i don't think returning Integer.MAX_VALUE is the correct answer if i have NO data
Never ascribe to malice that which can be adequately explained by stupidity.
Joined: Jan 11, 2006
Wouldn't you be better off using some type of collection like an ArrayList or something? Or do you have to use a simple Array?
Life can only be understood backwards; but it must be lived forwards. - Kierkegaard
Joined: Feb 24, 2006
Or you can write a simple bubblesort and then just get the lowest value in element 0. It might actually be faster this way, even with a slower sort algorithm like bubblesort.
Using ArrayList defeats the purpose of learning how to program. Which is better?
A. Someone who learns Java and a good chunk of the API, might even get one or two of those certificates of dubious value.
B. Someone who learns how to program, understands the underlying contructs of library classes and computers themselves and can easily move to other languages and even write their own libraries and therefore can leverage existing libraries better then A.