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); } ______________________ }

Respuesta :

Answer:

Following are the expression to this question:

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

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.