Question
The question is this Assume an integer variable, seconds, has been initialized to a number of seconds. Express few lines of code ending with a
The question is this
Assume an integer variable, seconds, has been initialized to a number of seconds. Express few lines of code ending with a printf statement that displays the number of hours, minutes, and seconds in that number of seconds in the format, hh:mm:ss, where hh is the zero-padded two-digit number of hours, mm is the zero-padded two-digit number of minutes, and ss is the zero-padded two-digit number of seconds in the value stored in seconds. For example, if seconds is 3661, then the display would be: 01:01:01. No if-statements are needed. Use only integer division and the remainder operator.
import java.util.Scanner;
public class TimeClock {
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
System.out.print("Input Seconds: ");
int seconds = kb.nextInt();
int hours = seconds/3600;
int minutes = (seconds/60)%60;
int secs = seconds%60;
System.out.printf("%d hours:%d minutes:%d secs");
}
}
This is what I figured out so far, but the program shows error on this. Please help
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started