Question:
How to convert seconds to hours/minutes/seconds?
Code:
import java.util.Scanner; public class Seconds { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter the number of seconds: "); int input = sc.nextInt(); int hours = input / 3600; int minutes = (input % 3600) / 60; int seconds = (input % 3600) % 60; System.out.println("Hours: " + hours); System.out.println("Minutes: " + minutes); System.out.println("Seconds: " + seconds); } }
Output:
$ java Seconds Enter the number of seconds: 50391 Hours: 13 Minutes: 59 Seconds: 51