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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!