Questions
Questions

(862646) AP CS A Unit 1 Exam  第一单元考试

Single choice

There are two integer variables in our program, hours and days, which represents time. If in the program, we increase the number of hours by one, which of the following lines of code will correctly update days and hours? 我们的程序中有两个整型变量,hours 和 days,它们代表时间。如果在程序中,我们将小时数增加 1,以下哪一行代码可以正确更新 days 和 hours?

Options
A.hours = hours % 24;
B.days = days + hours / 24; hours = hours % 24;
C.days = days + hours / 24;
D.days = days + hours % 24; hours = hours / 24;
E.hours = hours + days % 24;
View Explanation

View Explanation

Verified Answer
Please login to view
Step-by-Step Analysis
Question restatement: There are two integer variables, hours and days, representing time. If we increase hours by 1, which line of code correctly updates days and hours? Option 1: hours = hours % 24; - Why this is not correct: This only reduces hours to the remainder after division by 24 and does not touch days at all. It fails to carry full days from hours into the days variable. Option 2: days = days + hours / 24; \nhours = h......Login to view full explanation

Log in for full answers

We've collected over 50,000 authentic exam questions and detailed explanations from around the globe. Log in now and get instant access to the answers!

More Practical Tools for International Students

Join us and instantly unlock extensive past papers & exclusive solutions to get a head start on your studies!