Search

조건문2_문제07_자리숫자합

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

영상

문제

<script> /* [문제] [1] 10000~90000 사이의 랜덤 숫자 저장한다. [2] 앞에서부터 두 번째 자리와 네 번째 자릿수의 합을 출력하시오. [예] 랜덤숫자 : 57249 두 번째 자릿수 : 7 네 번째 자릿수 : 4 합 : 11 */ </script>
Java
복사

해설

<script> /* [문제] [1] 10000~90000 사이의 랜덤 숫자 저장한다. [2] 앞에서부터 두 번째 자리와 네 번째 자릿수의 합을 출력하시오. [예] 랜덤숫자 : 57249 두 번째 자릿수 : 7 네 번째 자릿수 : 4 합 : 11 */ let num = Math.floor(Math.random() * 80001) + 10000; // [0 ~ 80000] + 10000 console.log("num = " + num); document.write("num = " + num + "<br>"); let num1 = parseInt(num % 10000 / 1000); console.log("두 번째 자릿수 = " + num1); document.write("두 번째 자릿수 = " + num1 + "<br>"); let num2 = parseInt(num % 100 / 10); console.log("두 번째 자릿수 = " + num2); document.write("두 번째 자릿수 = " + num2 + "<br>"); let result = num1 + num2; console.log("합 = " + result); document.write("합 = " + result + "<br>"); </script>
Java
복사