Java数组题求代码
Java数组题求代码
public class Grade {
private int score[] = { 43, 50, 60, 65, 71, 78, 84, 89, 93, 98 }
private int sum = 0
public void count() {
int a = 0, b = 0, c = 0, d = 0, e = 0
for (int i = 0 i <= score.length - 1 i ) {
sum = score[i]
if (score[i] < 60) {
a
} else if (score[i] < 70 && score[i] >= 60) {
b
} else if (score[i] < 80 && score[i] >= 70) {
c
} else if (score[i] < 90 && score[i] >= 80) {
d
} else {
e
}
}
float avg = (float)sum / score.length
System.out.println("总分数为:" sum ";平均分数为:" avg)
System.out.println("不及格人数为:" a)
System.out.println("60~70分人数为:" b)
System.out.println("70~80分人数为:" c)
System.out.println("80~90分人数为:" d)
System.out.println("90分以上人数为:" e)
}
public static void main(String[] args) {
new Grade().count()
}
}