统计成绩

来源:互联网 发布:数据库主键有什么用 编辑:程序博客网 时间:2024/06/02 13:52
package lan3;/*描述 一个班有N(N <20)名学生,每个学生修了五门课。编写程序: 1)求每个学生的平均成绩,并输出每个学生的学号,每门课程的成绩及平均值。 2)求某门课程的平均分; 要求: 1) 分别编写2个函数实现以上2个要求。 2) 第1个函数用数组名作形式参数。第2个函数用指针作形式参数,并在函数体内用指针对数组操作。 输入 第一行:输入N,代表N名学生。 下面N行,每行有6个数据分别为:学号,英语成绩,数学成绩,C++成绩,音乐成绩,美术成绩 输出 首先输出N行:每行为学生学号,每门成绩和平均成绩(平均成绩四舍五入保留一位小数); 最后按顺序输出每门平均成绩(平均成绩四舍五入保留一位小数) 样例输入 4 20070001 94 92 97 93 90 20070005 84 89 92 81 73 20070004 82 75 94 86 95 20070003 84 86 82 97 91 样例输出 20070001 94 92 97 93 90 93.2 20070005 84 89 92 81 73 83.8 20070004 82 75 94 86 95 86.4 20070003 84 86 82 97 91 88.0 86.0 85.5 91.3 89.3 87.3 */import java.util.*;import java.text.DecimalFormat;public class Main9 {public static int n;public static String[] str;public static int[][] ch;public static double sumO;public static DecimalFormat df;public static void main(String[] args) {Scanner sc = new Scanner(System.in);n = sc.nextInt();df = new DecimalFormat("0.0");str = new String[n];ch = new int[n][5];for (int i = 0; i < n; i++) {str[i] = sc.next();ch[i][0] = sc.nextInt();ch[i][1] = sc.nextInt();ch[i][2] = sc.nextInt();ch[i][3] = sc.nextInt();ch[i][4] = sc.nextInt();}for (int i = 0; i < n; i++) {System.out.print(str[i] + " ");sumO = 0.0;for (int j = 0; j < 5; j++) {sumO += ch[i][j];System.out.print(ch[i][j] + " ");}System.out.println(df.format(sumO / 5));}for (int i = 0; i < 5; i++) {sumO = 0;for (int j = 0; j < n; j++) {sumO += ch[j][i];}sumO = sumO / n * 100;if (sumO % 100 >= 5) {sumO += 1;// System.out.println(sumO);}System.out.print(df.format(sumO / 100) + " ");}}}

0 0