输入一批学生成绩,以-1作为结束标记。直接得出以下内容如图哦
统计这批学生中不及格(<60)、及格(60-69)、中(70-9)、良(80~89)、优(>90)的人数并求这批学生的平均分。
import java.util.Scanner;
public class Demo1 {
public static void main(String[] args) {
int a=0,b=0,c=0,d=0,e=0;
Scanner scanner=new Scanner(System.in);
int score;
do {
score =scanner.nextInt();
if (0<score && score<60){
a++;
}else if (60<=score && score<70){
b++;
}else if (70<=score && score<80){
c++;
}else if (80<=score && score<90){
d++;
}else if (90<=score && score<=100){
e++;
}
}while (score!=-1);
System.out.println("不及格的有"+a+"人");
System.out.println("及格的有"+b+"人");
System.out.println("中等的有"+c+"人");
System.out.println("良好的有"+d+"人");
System.out.println("优秀的有"+e+"人");
}
}
希望对题主有所帮助!可以的话,帮忙点个采纳!
public static void main(String[] args) {
double[] arr = {75.5, 80, 92.5, 64.5, 55, 87.5, 98, 53};
// 不及格(<60)人数
long count = Arrays.stream(arr)
.filter(socre -> socre <= 60)
.count();
// 不及格(<60)人数
double avg = Arrays.stream(arr)
.filter(socre -> socre <= 60)
.average()
.orElse(0);
// 其余类似 。。。
}