Complete Minimum-finding Program

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page

Answer:

The complete program is given below.

Complete Minimum-finding Program

As with the maximum-finding program, run this program with various sets of data and confirm that it works with all of them.

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 ] ;

    }
      
    System.out.println("The minimum of this array is: " + min );
  }
}      

QUESTION 16:

Could an enhanced for loop be used in this program?