Write a program to input the time in secondsusing scanner class. Display the time after converting itinto hours, minutes and seconds.Sample input:6354Sample output: 1 Hour 45 Minutes 54 Second
Answers
Answered by
1
Question:-
Write a program to input time in seconds using Scanner class. Display the time after converting into hours, minutes and seconds.
Program:-
Here is your program written in Java.
import java.util.*;
class Time
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter the time in seconds: ");
int t=sc.nextInt();
int x=t;
int h=t/3600;
t = t - (3600*h);
int m=t/60;
t=t - (60*m);
System.out.println(x+" seconds = "+h+" hours "+m+" minutes "+t+" seconds. ");
}
}
Similar questions
Computer Science,
3 months ago
Business Studies,
3 months ago
Physics,
6 months ago
English,
6 months ago
Environmental Sciences,
10 months ago