Listing 33.8 Your basic Run (Run.java) Page 534


#1

The math in formatDuration seems overly involved to me. I changed from this:

public static String formatDuration(int durationSeconds) { int seconds = durationSeconds % 60; int minutes = ((durationSeconds - seconds) / 60) % 60; int hours = (durationSeconds - (minutes * 60) - seconds) / 3600; return String.format("%02d:%02d:%02d", hours, minutes, seconds); }

to this:

public static String formatDuration(int durationSeconds) { int seconds = durationSeconds % 60; int minutes = (durationSeconds / 60) % 60; int hours = (durationSeconds / 3600); return String.format("%02d:%02d:%02d", hours, minutes, seconds); }

Is there any reason/benefit to the extra steps?


#2

I do the same change