Question: Kotlin Write a method named arrayMinMaxSum. It receives an IntArray and two Int values, min and max, in that order, as parameters. You should return

Kotlin

Write a method named arrayMinMaxSum. It receives an IntArray and two Int values, min and max, in that order, as parameters. You should return the sum of all the elements in the array that are between the min the max, inclusive.

For example, given the array {1, -4, 2, 24, -124} and the min and max 1 and 24, you would return 27: 1 + 2 + 24, since these are the values in the array greater than or equal to 1 and less than or equal to 24. Note that the minimum may be greater than or equal to the maximum, in which case you should return 0. (But you don't need code to handle this specific case.)

Note that this problem is a great fit for the for in loop!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!