//************************************************** // Program Name: secstotime.java // Author: Pat Moss // Date: Sept 17, 2005 Rev: 01 // // Convert input Seconds to Hours, Minutes, Seconds //************************************************** import java.util.Scanner; public class secstotime { public static void main (String[] args) { int inputsecs = 0; Scanner scan = new Scanner(System.in); System.out.println ("secstotime.java by pat moss"); System.out.println (""); System.out.print ("Enter a positive integer value for total seconds (0 to quit): "); inputsecs = scan.nextInt(); while (inputsecs != 0) // Use the sentinel value of 0 to terminate the loop { if(inputsecs < 0) { System.out.println ("Invalid input value. Please reenter a positive integer value."); } else { int totalsecs = inputsecs; int hrs = totalsecs / 3600; // divide by seconds in one hour totalsecs = totalsecs - hrs * 3600; int mins = totalsecs / 60; // divide by minutes in one hour totalsecs = totalsecs - mins * 60; int secs = totalsecs; System.out.print ("The equivalent amount of time is "); System.out.print (hrs + " hours "); System.out.print (mins + " minutes "); System.out.print (secs + " seconds"); System.out.println (""); } System.out.println (""); System.out.print ("Enter a positive integer value for total seconds (0 to quit): "); inputsecs = scan.nextInt(); } System.out.println ("All Done..."); } }