Common Array Algorithms
This chapter discusses how a for loop can be used to iterate over the elements of a one-dimensional array. In addition, it also discusses enhanced for loops. The chapter demonstrates the use of arrays to solve common problems such as finding sum, average, maximum, and minimum values of numbers stored in array. Pay attention to some of the common programming errors one can make while using arrays.
15. Finding the minimum in an Array
Answer:
Yes.
Finding the minimum in an Array
Here is a program that finds the minimum of an array. It is similar to the maximum-finding program:
class MinAlgorithm { public static void main ( String[] args ) { int[] array = { -20, 19, 1, 5, -1, 27, 19, 5 } ; int min; // initialize the current minimum ; // scan the array for ( int index=0; index < array.length; index++ ) { if ; } System.out.println("The minimum of this array is: " + min ); } } |
Question 15:
Fill in the blanks. Select from the following phrases.
min = array[8] min = array[0] min = array[ index ] array[ index ] == min array[ index ] > min array[ index ] < min index++You can copy and paste from the phrases into the blanks. (Hint: only some of the phrases are used.)