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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started