题目
(862646) AP CS A Unit 1 Exam 第一单元考试
单项选择题
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?
选项
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;
查看解析
标准答案
Please login to view
思路分析
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登录即可查看完整答案
我们收录了全球超50000道考试原题与详细解析,现在登录,立即获得答案。
类似问题
What symbol is used to find remainder of a floor division?
In Java, what is the function of the modulo?
Evaluate following code and identify value of variable ans. int inp = 724395, ans; ans = (inp / 100) % 10;
Evaluate following code and identify value of variable ans. int inp = 724395, ans; ans = (inp / 100) % 10;
更多留学生实用工具
希望你的学习变得更简单
加入我们,立即解锁 海量真题 与 独家解析,让复习快人一步!