Search

이차반복문4_개념02_토탈짝수

대분류
STEP07 이차반복문
문제 난이도
LV05
소분류
이차반복문4_개념

영상

개념

<script> /* [문제] [1] 1~50 사이의 랜덤 숫자에서 3의 배수 3개의 합을 total배열에 추가한다. [2] 위 내용을 총 다섯번 반복한다. [예시] 36 18 39 : 93 21 27 15 : 63 24 9 42 : 75 21 3 39 : 63 24 6 18 : 48 total = 93, 63, 75, 63, 48 */ let total = []; for(let i=0; i<5; i++) { let sum = 0; let count = 0; while(true) { let num = Math.floor(Math.random() * 50) + 1; if(num % 3 == 0) { document.write(num + " "); sum += num; count += 1; } if(count == 3) { break; } } document.write(": " + sum + "<br>"); total.push(sum); } document.write("total = " + total); </script>
Java
복사