Answer to Question #3759 in Java | JSP | JSF for Joe

Question #3759
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 ");
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS