计算大于平均年龄的员工人数
作者:互联网
package com.itheima.demo01;
/有以下数组int arr={31,42,23,64,25,36}存储了6名员工的年龄;
定义方法getCount(),
计算大于平均年龄的员工人数/
public class Bug08 {
public static void main(String[] args) {
int[] arr = {31, 42, 23, 64, 25, 36};
int count = getCount(arr);
System.out.println(count);
}
public static int getCount(int[] arr) {
double sum = 0;
for (int i = 0; i < arr.length; i++) {
sum += arr[i];
}
double avg = sum*1.0 / arr.length;
int count = 0;
for (int i = 0; i < arr.length; i++) {
if (arr[i] > avg) {
count++;
}
}
return count;
}
}
标签:count,arr,int,平均年龄,员工,public,length,大于,sum 来源: https://www.cnblogs.com/lvtiantian/p/14724697.html