/*문제: 12 [이중배열 [][] ]
  다섯 명의 국영수 점수를 계산하여 총점과 평균을 구하라
  각 학생의 총점과 평균은 배열에 저장하라.
  double[][] scores = {
  {60.5, 78.9, 95, 0, 0},
  {90, 85, 99, 0, 0},
  {80, 74, 98, 0, 0},
  {70, 82, 97, 0, 0},
  {60, 88, 96, 0, 0}
  };
  예) java Test
  출력 예:
  1: 총점 234.400000점, 평균 78.133333점
  2: 총점 274.000000점, 평균 91.333333점
  3: 총점 252.000000점, 평균 84.000000점
  4: 총점 249.000000점, 평균 83.000000점
  5: 총점 244.000000점, 평균 81.333333점
  전체 평균: 83.560000점

 

 

class Test{

 public static void main(String[] args) throws Exception {

   double allAverSum = 0.0;
   double[][] scores = {
     {60.5, 78.9, 95, 0, 0},
     {90, 85, 99, 0, 0},
     {80, 74, 98, 0, 0},
     {70, 82, 97, 0, 0},
     {60, 88, 96, 0, 0}
   };

   for (int row = 0; row < scores.length; row++) {
     for (int col = 0; col < 3; col++) {
       scores[row][3] += scores[row][col];
     }
     scores[row][4] = scores[row][3] / 3;
     allAverSum += scores[row][4];
   }

   for (int row = 0; row < scores.length; row++) {
     System.out.printf("%d: 총점 %f점, 평균 %f점 \n",
      row + 1, scores[row][3], scores[row][4]);
   }
   System.out.printf("전체 평균: %f점\n", allAverSum / scores.length);
  }
}

Posted by 안낭우훗

블로그 이미지
좋은싸이트 공유, 재해석 , 공부 정리, 틀린거 알려 주세요~
안낭우훗

태그목록

공지사항

Yesterday
Today
Total

달력

 « |  » 2025.5
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

최근에 올라온 글

최근에 달린 댓글

글 보관함