4.要求: (1)打印该班级的不及格人数 (2)打印该班级的平均分 (3)演示格式如下: 请输入班级人数: 键盘录入:100 控制台输出: 不及格人数:19 班级平均分:87 import java.util.Random; import java.util.Scanner; public class Demo01 { public static void main(String[] args) { Scanner sc = newScanner(System.in); System.out.println("请输入班级人数:"); int nextInt =sc.nextInt(); int[] arr = new int[nextInt]; int count = 0; int source = 0; int avg =0; Random random = new Random(); for(int i = 0 ; i < arr.length; i++){ arr = random.nextInt(101); System.out.println(arr); if(arr <60){ count++; } source += arr; } System.out.println("不及格人数:"+count); System.out.println("班级平均分:"+(source/arr.length)); } }
|