In this code, -20 should be the min since its negative and the farthest from zero correct? But when I run MinAlgoritm, the integer 5 is printed out. I have a Max version of this that works fine but this doesn't. How can this be? Are there any improvements I can make?
class MinAlgorithm
{
public static void main ( String[] args )
{
int[] array = { -20, 19, 1, 5, -1, 27, 19, 5 } ;
int min;
// initialize the current minimum
min = array[0];
// scan the array
for ( int index=0; index < array.length; index++ )
{
if (array[index]<min);
min=array[index];
}
// Print out the result
System.out.println("The minimum of this array is: " + min );
}
}