5명의 3과목 평균, 총합 구하기
public class TwoDimTest {
public static void main(String[] args) {
// 5명 학생 3과목(DB,JAVA,JSP점수 저장 배열)
int[][] score = {
{95,30,50},
{90,97,75},
{59,59,05},
{100,100,90},
{89,30,50}
};
int sumdb = 0;
int sumjava = 0;
int sumjsp = 0;
int sumtotal = 0;
float sumavg = 0f;
float avgdb = 0f;
float avgjava = 0f;
float avgjsp = 0f;
for(int i=0;i<score.length;i++){
for(int j=0;j<score[i].length;j++){
System.out.print(score[i][j]+" ");
}
System.out.println();
}
System.out.println();
for(int i=0;i<score.length;i++){ //5
sumdb += score[i][0];
avgdb = sumdb/score.length;
sumjava += score[i][1];
avgjava = sumjava/score.length;
sumjsp += score[i][2];
avgjsp = sumjsp/score.length;
for(int j=0;j<score[i].length;j++){
sumtotal += score[i][j];
}
sumavg = sumtotal/score[i].length;
System.out.println();
}
System.out.println("===================");
System.out.println("DB 총 점수 : "+ sumdb);
System.out.println("DB 평균 : "+ avgdb);
System.out.println("===================");
System.out.println("JAVA 총 점수 : "+ sumjava);
System.out.println("JAVA 평균 : "+ avgjava);
System.out.println("===================");
System.out.println("JSP 총 점수 : "+ sumjsp);
System.out.println("JSP 평균 : "+ avgjsp);
System.out.println("===================");
System.out.println("전체 점수 : "+ sumtotal);
System.out.println("전체 평균 : "+ sumavg);
System.out.println("===================");
}
}