168k views
4 votes
Select 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); } ______________________ }

1 Answer

3 votes

Answer:

Following are the expression to this question:

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

Step-by-step explanation:

function definition can be described as follows:

  • In the given method definition a method "sumTwoLowestElements" is declared, which accepts a single-dimensional integer array in method parameters.
  • Inside the method, "PriorityQueue" class object "values" is created, that uses a for loop, inside the loop an integer variable "num" is declared, that holds array value.
  • In the loop a class object uses add method, which is an inbuilt method, that adds all array values and outside the loop, a remove method is used that first selects two values then a remove from the return value.
User Linyaa
by
4.1k points