日期:2014-05-20 浏览次数:20734 次
public class Test { public static String arrName[] = {"李五常", "张大圆", "魏华", "王丽丽"} ; public static String arrCourse[] = {"Java", "计算机基础", "操作系统"} ; public static int arrScore[][] = { {90, 78, 82, 87}, {80, 90, 78, 66}, {88, 77, 79, 70} } ; /** * 指定人的平均分 * @param personIdx * @param courseIdx * @return */ public static double avgPerson(int personIdx){ int oneLen = arrScore.length ; double sum = 0.0 ; for (int i = 0; i < oneLen ; i++){ sum += arrScore[i][personIdx] ; } return sum / oneLen; } /** * 指定科目的平均分 * @param personIdx * @param courseIdx * @return */ public static double avgCourse(int courseIdx){ int oneLen = arrScore.length ; double sum = 0.0 ; for (int i = 0; i < oneLen ; i++){ sum += arrScore[courseIdx][i] ; } return sum / oneLen; } /** * @param args */ public static void main(String[] args) { System.out.println("------各科目平均分------"); for (int i = 0; i < arrCourse.length; i++){ System.out.println(arrCourse[i] + " 的平均分:" +avgCourse(i)); } System.out.println("------个人平均分------"); for (int i = 0; i < arrName.length; i++){ System.out.println(arrName[i] + " 的平均分:" +avgPerson(i)); } } }