Computer Science, asked by lathashreegtch, 6 months ago

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 anindyaadhikari13
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