영상
개념
<script>
/*
[문제]
[조건1] 30의 약수를 출력하고,
[조건2] 그 총합을 구하시오.
[조건3] 그 개수를 구하시오.
[정답]
1 2 3 5 6 10 15 30
합 = 72
개수 = 8
*/
let num = 30;
let total = 0;
let count = 0;
let i = 1;
while(i <= num) {
if(num % i == 0) {
console.log(i);
document.write(i + " ");
total += i;
count += 1;
}
i += 1;
}
console.log("합 = " + total);
console.log("개수 = " + count);
document.write("<br>");
document.write("합 = " + total + "<br>");
document.write("개수 = " + count);
</script>
Java
복사