Write a Java method isAverageInRange
时间: 2024-06-04 19:11:52 浏览: 56
public static boolean isAverageInRange(int[] array, int lowerBound, int upperBound) {
if(array.length == 0) {
return false;
}
double sum = 0;
for(int i = 0; i < array.length; i++) {
sum += array[i];
}
double average = sum / array.length;
return average >= lowerBound && average <= upperBound;
}
// This method takes an array of integers and two integer bounds as input parameters,
// and returns true if the average of the integers in the array is within the range
// specified by the two bounds (inclusive), and false otherwise. If the array is empty,
// the method returns false.
阅读全文