Java !!!/step_3

5명 학생 3과목의 점수, 평균, 총점 등등

asdwasd12as 2015. 3. 27. 14:06

//2. 5명 학생의 국,영,수 점수를 입력받아 학생별 총점,평균
  //                            과목별 총점 출력
  // 1번학생 : 국 영 수 총점 평균
  // 2번학생 : 국 영 수 총점 평균
  // 총점 : 국어 합계, 영어 합계, 수학 합계
  int score[][] = new int[5][3]; // 학생 5명, 3과목
  int sTotal[] = new int[5]; // 학생
  int ScoreTotal[] = new int[3]; // 과목별 총점
  Scanner scan = new Scanner( System.in );
  int snum = 0;
  int cnt = 1;
  
  for( int i=0 ; i<score.length ; i++ ){
   cnt = 1;
   System.out.println( (cnt+i )+ "번째학생 점수");
   for( int j=0 ; j<score[i].length ; j++ ){
    cnt = 1;
    System.out.println("점수" + (cnt+j) + ":");
    snum = scan.nextInt();
    score[i][j] = snum;
   }
   System.out.println();
  }
  
  // 결과 출력
  System.out.println("번호\t국어\t영어\t수학\t총점\t평균");
  System.out.println("============================================");
  int ccnt = 1;
  int Total = 0;
  for( int i=0 ; i<score.length ; i++ ){
   System.out.print( ccnt + "번\t");
   for( int j=0 ; j<score[i].length ; j++ ){
    System.out.print(score[i][j] + "\t");
    Total += score[i][j];
   }
   System.out.print(Total + "\t");  // 학생 총 점수
   System.out.print( (float)Total/3 );  // 학생 점수 평균
   System.out.println();
   Total = 0;
   ccnt++;
  }
  
  System.out.println("============================================");
  System.out.print("총점\t");
  int[] sss = new int[3];
  for( int j=0 ; j<score.length ; j++ ){
   for( int i=0 ; i<3 ; i++ ){
    sss[i] += score[j][i];
   }
  }
  for( int i=0 ; i<ScoreTotal.length ; i++ ){
   System.out.print(sss[i] + "\t");
  }