public class Score {//2차원 배열로 성적 출력 public static void main(String[] args){ int[][] score = { {100,100,100}, {20,20,20}, {30,30,30}, {40,40,40}, {50,50,50} }; System.out.println("번호 국어 영어 수학 총점 평균"); System.out.println("=================="); for(int i=0; i <score.length; i++){ int sum=0; System.out.print(" " + (i + 1) + " "); //i + 1은 번호를 출력하기 위함 +1안하면 0 으로됨 for(int j=0;j < score[i].length;j++){ sum+=score[i][j]; //총점 얻기위한 누적 System.out.print(score[i][j]+" ");//과목 점수 출력 } System.out.println(sum + " " + sum/score[i].length); //총점 나누기 과목갯수로 평균값 구하기 } } }
'Java > Array(배열)' 카테고리의 다른 글
2차 배열로 성적 작성(값 받아오기) (0) | 2012.04.09 |
---|---|
배열로 성적 짜기 (값을 직접 입력받아서) (0) | 2012.04.09 |
2차원 배열 선언,생성,초기화 (0) | 2012.04.09 |
2차원 배열 Array (0) | 2012.04.09 |
배열 Array (0) | 2012.04.09 |