//배열의 총합과 평균
int sum=0;
float avg=0;
int[]score= {100,88,100,100,90};
for(int i=0;i<score.length;i++)
sum+=score[i];
avg=sum/(float)score.length; //계산결과를 float로 얻기 위해 형변환
System.out.println("총점: "+sum);
System.out.println("평균: "+avg);
//결과
총점: 478
평균: 95.6
'자바의 정석 문제풀이' 카테고리의 다른 글
Book_218_5_19(2차원배열+과목별 점수) (0) | 2021.08.10 |
---|---|
Book_197_5_06(배열의 최대값,최소값) (0) | 2021.08.09 |
Book_186_5_01(배열의 길이와 인덱스) (0) | 2021.08.09 |
Book_194_5_03(배열의 복사) (0) | 2021.08.09 |
Book_163_4_18 (0) | 2021.08.06 |