Answer:
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 val : array )
{
if ( val < min )
min = val ;
}
System.out.println("The minimum of this array is: " + min );
}
}
Summing the numbers in an Array
Say that you wanted to compute the sum of a list of numbers.
You could start with
the number on the left,
and then proceed left to right through the remaining numbers.
Here is a program that implements that algorithm.
Its array
contains values of type double.
QUESTION 18:
Complete the program by filling in the blanks.