The locked code in your editor passes array(of size ) and index to the print method, whose try block attempts to print element ; if is Out-of-Range, an Array Index Out Of Bounds Exception is thrown.
Complete the code in your editor so that it prints the maximum and minimum elements in array—regardless of whether or not an exception is thrown.
The first line contains an integer,
The second line contains space-separated integers describing .
The third line contains an index, , to be accessed.
Note: Input from stdin handled by the locked code in the editor.
The try block will print the value accessed at
You must print the respective maximum and minimum values in array as a single pair of space-separated integers on a new line—regardless of whether an exception is thrown.
Note: Observe that your max/min values may print on either the first or second line, depending on whether or not an Exception was thrown!
Sample Input 0
12 -12 0 1 -899 23 45 96 10 75 23 0 33 100
Sample Output 0
96 -899 java.lang.ArrayIndexOutOfBoundsException
Sample Input 1
10 4 908 -05 445 -208 325 -2 -718 863 400 9
Sample Output 1
400 908 -718
, , , and
‘s indices range from to , so attempting to access index throws an Exception. The maximum and minimum values in the array are printed on a new line as a pair of space-separated integers. The program’s control flow then returns to main where the the Exception is caught and printed on a new line.
, , , and
‘s indices range from to , so an attempt to access index will be successful and the value at (i.e.: ) is printed on a new line. The program’s control flow then proceeds to print the maximum and minimum values in as a pair of space-separated integers on a new line.