영상
문제
<script>
/*
[문제]
a 와 b 의 각 자리의 합을 total에 저장하시오.
[정답]
[64, 49, 27, 24, 103]
*/
let a = [10, 43, 23, 12, 53];
let b = [54, 6, 4, 12, 50];
let total = [0, 0, 0, 0, 0];
</script>
Java
복사
해설
<script>
/*
[문제]
a 와 b 의 각 자리의 합을 total에 저장하시오.
[정답]
[64, 49, 27, 24, 103]
*/
let a = [10, 43, 23, 12, 53];
let b = [54, 6, 4, 12, 50];
let total = [0, 0, 0, 0, 0];
for(let i=0; i<5; i++) {
let sum = a[i] + b[i];
total[i] = sum;
}
document.write(total + "<br>");
//---------------------------------------
let i = 0;
while(i < 5) {
total[i] = a[i] + b[i];
i += 1;
}
document.write(total + "<br>");
</script>
Java
복사