10.9k views
4 votes
Select

public static int sumTwoLowestElements(int[] numbers) { PriorityQueue values = new PriorityQueue<>(); for (int num: numbers) { values.add(num); } ______________________ }
an appropriate expression to complete the following method, which is designed to return the sum of the two smallest values in the parameter array numbers.
public static int sumTwoLowestElements(int[] numbers) { PriorityQueue values = new PriorityQueue<>(); for (int num: numbers) { values.add(num); } ______________________ }

User Reedcourty
by
4.5k points

1 Answer

3 votes

Answer:

return values.remove() + values.remove();

Step-by-step explanation:

The appropriate expression to complete the method, which is designed to return the sum of the two smallest values in the parameter array number is indicated below in bold font :

public static int

sumTwoLowestElements(int[] numbers)

{

PriorityQueue values = new PriorityQueue<>();

for (int num: numbers)

{ values.add(num);

}

return values.remove() + values.remove();

}

The return statementin programming is often used when a function is ready to return a value to its caller.

User Michael Brennan
by
5.7k points