Java分析学生成绩

利用一维数组进行分析


public class 分析成绩 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner input = new Scanner(System.in);
		System.out.println("Enter the grades");
		int[] a = new int[100];
		int count = 0, m = 0;
		while (true) {
			int temp = input.nextInt();
			if (temp < 0)
				break;
			a[count] = temp;
			m += temp;
			count++;
		}
		int average;
		average = m / count;
		int l = 0, r = 0;
		for (int i = 0; i < count; i++) {
			if (a[i] < average)
				l++;
			else
				r++;
		}
		System.out.println("低于平均分的人数为" + l + "高于平均分的人数为" + r);
	}

}

你可能感兴趣的:(Java分析学生成绩)