THINK FIRST·CODE LATER

← All labs

Average speed of a cyclist

Problem

A cyclist rides 24 km in 1 hour 15 minutes and 30 seconds. Write AverageSpeed, which lets Java compute the speed step by step, using only println and arithmetic expressions (no variables yet). One mile is 1.6 km. The program prints exactly:

30 / 60 with whole numbers: 0
30 / 60.0 with a real number: 0.5
Time in minutes: 75.5
Time in hours: 1.2583333333333333
Speed in km/h: 19.072847682119207
Speed in miles/h: 11.920529801324504

The first two lines show the trap of this lab: why is 30 / 60 zero?

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.