국영수 성적 평균, 총점 구하기
package day08;
public class ArrayEx7 {
public static void main(String[] args) {
int[][] score = { { 100, 100, 100}
, { 20, 20, 20}
, { 30, 30, 30}
, { 40, 40, 40}
, { 50, 50, 50}};
int koreanTotal = 0;
int englishTotal = 0;
int mathTotal = 0;
System.out.println("번호 국어 영어 수학 총점 평균 ");
System.out.println("===============================================");
for(int i=0;i < score.length;i++) {
int sum=0;
koreanTotal += score[i][0];
englishTotal += score[i][1];
mathTotal += score[i][2];
System.out.print(" " + (i + 1) + "\t");
for(int j=0;j < score[i].length;j++) {
sum+=score[i][j];
System.out.print(score[i][j]+"\t");
}
System.out.println(sum + "\t" + sum/(float)score[i].length);
}
System.out.println("===============================================");
System.out.println("총점: " + koreanTotal + "\t" +englishTotal +"\t" +mathTotal);
}
}
출력결과
번호 국어 영어 수학 총점 평균
===============================================
1 100 100 100 300 100.0
2 20 20 20 60 20.0
3 30 30 30 90 30.0
4 40 40 40 120 40.0
5 50 50 50 150 50.0
===============================================
총점: 240 240 240