Write a program that request a time interval in seconds and display it in hours, minutes, second format. (java)
import java.util.Scanner; // Import the Scanner class
class TimeFrame {
public static void main(String[] args) {
int x,h,m,s;
Scanner myObj = new Scanner(System.in); // Create a Scanner
object
System.out.println("Enter Time in seconds:");
x = myObj.nextInt(); // Read user input
h= x/3600; // converting to hours
x=x%3600; // getting remaining seconds to convert into mins
m=x/60; //converting into mins
s=x%60; // converting into secs
System.out.println("Given seconds in time format : "+h+" hrs "+m+"
mins "+s+" secs"); // Print the time
}
}
Get Answers For Free
Most questions answered within 1 hours.