67 232
Assignments Done
99,2%
Successfully Done
In November 2018

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.
Expert's answer
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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions