public int min()
{
int min = elementData[0];
for (int i = 1; i < size; i++)
{
if (elementData[i] < min)
{
min = elementData[i];
}
}
return min;
}
private static int findMin(int[] array) {
int min = array[0];
for(int i=1;i<array.length;i++) {
if(min > array[i]) {
min = array[i];
}
}
return min;
}
int /*OR*/ double /*OR*/ float[] array_of_numbers = {/*Whatever values you want*/}
/*For this example we're just using a regular integer array*/
int min = array_of_numbers[0]; /*Important to initialise the first value!!!!*/
for (int i = 0; i < array_of_numbers.length; i++) {
if(array_of_numbers[i] < min) { /* So now we can make the comparison*/
min = array_of_numbers[i]; /* If smaller, make it the new minimum*/
}
}
System.out.println("Minimum value in array: " + min)