영상
문제
<script>
/*
[문제]
철수는 도서관에서 책을 한 권 빌렸다.
빌린 날짜는 2022년 2월 25일이고, 대여 일수는 10일이다.
도서가 연체되면 연체 비용은 하루에 100원이다.
오늘은 2022년 3월 10일 이라고 할 때,
지급해야 하는 비용은 얼마인지 구하시오.
단, 윤년은 계산하지 않는다.
[정답]
300원
*/
let monthList = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
</script>
Java
복사
해설
<script>
/*
[문제]
철수는 도서관에서 책을 한 권 빌렸다.
빌린 날짜는 2022년 2월 25일이고, 대여 일수는 10일이다.
도서가 연체되면 연체 비용은 하루에 100원이다.
오늘은 2022년 3월 10일 이라고 할 때,
지급해야 하는 비용은 얼마인지 구하시오.
단, 윤년은 계산하지 않는다.
[정답]
300원
*/
let monthList = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
let period = 10;
let thisMonth = 3;
let thisDay = 10;
let thisTotal = 0;
for(let i=0; i<thisMonth - 1; i++) {
thisTotal += monthList[i];
}
thisTotal += thisDay;
document.write("thisTotal = " + thisTotal + "<br>");
let rentMonth = 2;
let rentDay = 25;
let rentTotal = 0;
for(let i=0; i<rentMonth - 1; i++) {
rentTotal += monthList[i];
}
rentTotal += rentDay;
document.write("rentTotal = " + rentTotal + "<br>");
let result = thisTotal - rentTotal - period;
if(result <= 0) {
document.write("기간 내에 반납해주셔서 감사합니다.");
} else {
let price = result * 100;
document.write("연체된 기간 = " + result + "<br>");
document.write("연체 비용은 " + price + "원 입니다.")
}
</script>
Java
복사