14.7k views
1 vote
(Hours, minutes, and seconds) Write a method that returns a string in the form of hour:minute:second for a given total seconds using the following header:

public static String format(long seconds)
Here is a sample run:

Enter total seconds: 342324
The hours, minutes, and seconds for total seconds 342324 is 23:05:24

Note that a zero is padded to hour, minute, and second if any of these values is a single digit.

1 Answer

4 votes

Answer:

Answered below.

Step-by-step explanation:

class Convert {

public static String format(long seconds) {

Scanner sc = new Scanner(System.in);

System.out.print("Enter total seconds: ");

int secs = sc.nextInt();

int hours = secs / 3600;

int minutes = (secs % 3600) / 60;

int seconds = (secs % 3600) % 60;

String timeFormat = hours + ":" + minutes + ":" + seconds;

return timeFormat;

}

}

User Domoarigato
by
3.5k points