numbers.text contains a header value, followed by that many double values. Create an array of the
appropriate size, populate the array with the doubles, and print out various information about the array (see below).
Sample Test Run
For example if the file numbers.text contains:
8 12.3 2.5 9.4 3.14 22.15 17 54.3 7.6the program should produce the following output:
The array: {12.3, 2.5, 9.4, 3.14, 22.15, 17.0, 54.3, 7.6} contains 8 elements
The first element of the array is 12.3
The last element of the array is 7.6 and is at position 7
The middle element of the array is 3.14 and is at position 3
The largest element of the array is 54.3 and is at position 6
The smallest element of the array is 2.5 and is at position 1
Notes:
first,
last, or middle methods — — feel free to simply use the proper subscripts).
max method presented inthe lecture notes is useful, it is not enough; you are not just being
asked to print out the largest and smallest value, you are also required to print out their positions (i.e., indexes in the
array). You thus should consider writing a maxPos method that returns the index (rather than the actual value)
of the largest element in the array (same for minimu).
max method; this also emphasizes the distinction between the value of the element
and its index (position/location within the array).
numbers.text contains a header value, followed by that many integer values. Read the values into
an array, and print them out in reverse to the file reversed.text, preceded by a header value.
Sample Test Run
For example if the file numbers.text contains:
5 10 20 30 40 50the program should produce the following output:
5 50 40 30 20 10