Write a Java program that reads in a positive integer representing time in seconds and converts it to hour, minute and seconds. for example, if the inputs is 3670 seconds, it works out to be 1 hour, 1 minute and 10 seconds.
1
Expert's answer
2011-07-29T14:30:30-0400
import java.util.*;public class Seconds { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int sec = scan.nextInt(); if (sec < 0) { System.out.println("Negative input"); return; } int hour = sec / 3600; sec -= hour * 3600; int minute = sec / 60; sec -= minute * 60; System.out.println(hour + " hour " + minute + " minute " + sec + " seconds "); } }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment