Search

반복문3_개념06_배수_개수

대분류
STEP03 조건문/일차반복문
문제 난이도
필수
소분류
일차반복문3_개념

영상

개념

<script> /* [문제] 5~15 사이의 숫자 중에서 [조건1] 4의 배수를 출력하고, [조건2] 그 총합을 구하시오. [조건3] 그 개수를 출력하시오. [정답] 8 12 합 = 20 개수 = 2 */ let total = 0; let count = 0; let i = 5; while(i <= 15) { if(i % 4 == 0) { console.log(i); document.write(i + "&nbsp;"); total += i; count += 1; } i += 1; } console.log("합 = " + total); console.log("개수 = " + count); document.write("<br>") document.write("합 = " + total + "<br>"); document.write("개수 = " + count); </script>
Java
복사