//[?] n명의 국어 점수 중에서 80점 이상인 점수의 합계
/**
* 합계 알고리즘: 주어진 범위에 주어진 조건에 해당하는 자료들의 합계
*/
public class SumAlgorithm2 {
public static void main(String[] args) {
int[] scores = { 100, 75, 50, 37, 90, 95 };
int sum = 0; // 결과값 담김
for (int i = 0; i < scores.length; i++) { // 범위 지정(=> 0에서 scores.length까지)
if(scores[i] >= 80) { // 만약에 scores배열의 i 번째 데이터가 80보다 크거나 같다면
sum += scores[i]; // SUM 영역 (=> sum에 누적을 시켜라)
}
}
System.out.println(scores.length + "명의 점수 중 80점 이상의 총점: " + sum);
}
}
출력값: 6명의 점수 중 80점 이상의 총점: 285
'Dev > Java' 카테고리의 다른 글
5. 최솟값 알고리즘 (Min Algorithm) (0) | 2022.08.08 |
---|---|
4. 최댓값 알고리즘 (Max Algorithm) (0) | 2022.08.08 |
3. 평균 알고리즘(Average Algorithm) (0) | 2022.08.08 |
2. 개수 알고리즘(Count Algorithm) (0) | 2022.08.08 |
1-1. 등차수열(Arithmetic Sequence) (0) | 2022.08.08 |
댓글