课堂练习:统计不及格人数
统计score[ ]={37,89,63,60,59,78,91}
中成绩不及格的人数,并打印输出。(当然,可以添加更多成绩数据进行处理。)
运行代码:
public class _4_1_3_DealScores {
public static void main(String[] args) {
//1. 数组的声明
double[] score;
//2. 创建数组
score = new double[] {
37,89,63,60,59,78,91};
//3. 数组的使用
int failed = 0;//不及格人数
for (int i = 0; i < score.length; i++) {
if (score[i] < 60) {
failed++;
}
}
System.out.println("不及格人数:"+failed);
}
}