/* Seconds.java * Author: Anders * * Translated by: Jesper * * Exercise 7: * Converts a number of seconds to the equivalent * number of days, hours, minutes and seconds. */ import cs1.Keyboard; public class Seconds{ public static void main(String[] args){ // The number of seconds to be // converted is read from the keyboard System.out.print("Enter a number of seconds: "); int totalSeconds = Keyboard.readInt(); final int k1 = 60; //Number of seconds in a minute. final int k2 = k1*60; //Number of seconds in a hour. final int k3 = k2*24; //Number of seconds in a day. // Days, hours, minutes and seconds are calculated int doegn = totalSeconds/k3; int timer = (totalSeconds%k3)/k2; int minutter = (totalSeconds%k2)/k1; int sekunder = totalSeconds%k1; // The result is printed System.out.println(totalSeconds + " seconds equals " + doegn + " days, " + timer + " hours, " + minutter + " minutes and " + sekunder + " seconds."); } // End of the main method } //End of the class