Computer Science, asked by SpaceWalker17, 7 months ago

7. Write a program to input the time in seconds. Display the time after converting them into hours, minutes and seconds. Sample Input : Time in seconds 5420 Sample Output : 1 hour 30 minutes 20 seconds. please don't spam...❤✌​

Answers

Answered by akankshsksinha7
86

Answer:

Hey mate !! Here is ur answer....

Explanation:

import.java.util*

Public Class Seconds

{

public static void main(String args [] )

{

Scanner in = new Scanner ( System.in);

System.out.println(" time in seconds");

Float seconds = in.next float();

Float hours= seconds / 3600;

Float mins = seconds /60;

Float seconds= S %60;

System.out.println( "hrs"+hours "minutes"+ mins "seconds"+seconds);

}

}

Answered by qwmillwall
2

Seconds Converter

  • To convert seconds we have to first divide the seconds by 3600, we will get the hours. Since 1 hr has 3600 seconds.
  • Now to get the remaining seconds we will perform the modulo operator, i.e., second % 3600.
  • To calculate minutes, divide the remaining seconds by 60, since 1 minute has 60 seconds, and then perform modulo 60 to get the remaining seconds.
  • In the end print the answer in the given pattern.

Python Code:

seconds = int(input("Enter the seconds:"))

hours = seconds // 3600

seconds = seconds % 3600

mins = seconds // 60

seconds = seconds % 60

print(hours, "hour", mins, "minutes", seconds, "seconds")

Output:

1 hour 30 minutes 20 seconds

#SPJ2

Similar questions