THINK FIRST·CODE LATER

← All labs

Let Java do the arithmetic

Problem

Write QuickMath: eight println statements, each printing a label and a value that Java computes (do not type the results yourself). The program takes no input and must print exactly:

7 + 2 * 3 = 13
(7 + 2) * 3 = 27
7 / 2 = 3
7 % 2 = 1
7 / 2.0 = 3.5
Days in 10 weeks: 70
Hours in a year: 8760
Seconds in a day: 86400

Before running it, predict lines 3, 4 and 5. Why are 7 / 2 and 7 / 2.0 different?

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.