Exercises 14.13 Chapter Exercises
1.
2.
Add a set of parentheses to the expression
x = 6 * 1 - 2
so that the code below prints -6 instead of 4.3.
Add parentheses to
x = 12 * 2 - 3 + 4 * 2
so that it prints -4 instead of 29.4.
5.
It is currently 10:00, complete the code to tell what time it is going to be in 18 hours (using 12-hour time, not 24-hour time). Use the
%
(modulo or remainder operator) to calculate the correct value for clockTime based on the newTime value that is already calculated.The answer should be 4 because 28 hours divided into 12-hour chunks leaves a remainder of 4. But make sure not to hardcode the answer - you need to calculate the value, not just type it in.
6.
Finish the code on lines 2 and 3 in the code below to print how many hours and minutes you have been waiting when you have been waiting a total of 270 minutes.
Use the
%
(modulo or remainder operator) and the integer division operator //
to calculate the correct values for numHours and numMinutes based on the totalMinutes value.The correct answers should be 4 for numHours and 30 for numMinutes. But make sure to calculate those values - don’t hardcode them!
You have attempted 1 of 7 activities on this page.