75.4k views
8 votes
Write a method that accepts a number of seconds and prints the correct number of hours, minutes, and seconds.

User Kindzoku
by
3.1k points

1 Answer

7 votes

Answer:

This solution is implemented in Java

public static void timme(int seconds) {

int hours = seconds/3600;

System.out.println("Hours: "+hours);


seconds = seconds - hours * 3600;

int minutes = seconds/60;

System.out.println("Minutes: "+minutes);


seconds = seconds - minutes * 60;

System.out.println("Seconds: "+seconds);

}

Step-by-step explanation:

This method defines the method along with one parameter

public static void timme(int seconds) {

This calculates hours from the seconds

int hours = seconds/3600;

This prints the calculated hours

System.out.println("Hours: "+hours);

This calculates the seconds remaining


seconds = seconds - hours * 3600;

This calculates the minutes from the seconds left

int minutes = seconds/60;

This prints the calculated minutes

System.out.println("Minutes: "+minutes);

This calculates the seconds remaining


seconds = seconds - minutes * 60;

This prints the seconds left

System.out.println("Seconds: "+seconds);

}

User SLC
by
3.4k points