Find min and max

Report a typo

You have an outer class ArrayCalc and a static nested class MinMaxPair inside.

Complete the method MinMaxPair that finds the min and max elements of an array.

Motivation: our goal is to find the minimum and the maximum element of an array. Of course, it can be done by two different methods, but a special structure MinMaxPair will allow going through an array only once, which is more effective.

Sample Input 1:

0 1 2 3 4 5 6 7 8 9

Sample Output 1:

min = 0
max = 9
Write a program in Java 17
import java.util.Scanner;

class ArrayCalc {

// static nested class
public static class MinMaxPair {
private int min;
private int max;

public MinMaxPair(int first, int second) {
this.min = first;
this.max = second;
}

public int getMin() {
return min;
}

public int getMax() {
return max;
}
}

// find min and max elements
public static MinMaxPair findMinMax(int[] array) {

// write your code

return new MinMaxPair(min, max);
}
}

class Main {

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
___

Create a free account to access the full topic