+ 1

Write a program in java to input time in second and output the time in hour minute and seconds

solve this please i am having prodlem in making this program

12th Feb 2017, 12:42 PM
sameer sahu
sameer sahu - avatar
2 ответов
+ 1
Little hint: You could simply use div and mod ( / and % ) to solve the problem. What do you have got so far?
12th Feb 2017, 2:08 PM
Tashi N
Tashi N - avatar
+ 1
Not sure about the posting rules, but this should help: public static void main(String[] args) { int secondsLeft, usedSeconds; int secondsInHour = 3600; //60 mins in an hour, 60 mins in a minute int minutes, hour, seconds; Scanner in = new Scanner(System.in); System.out.print("Enter the number of seconds: "); seconds = Integer.parseInt(in.next()); hour = seconds / secondsInHour; //calculates the number of hours secondsLeft = seconds % secondsInHour; //calculates the number of seconds remaining minutes = secondsLeft / 60; //calculates the number of minutes from the remaining seconds usedSeconds = hour * 3600 + minutes * 60; secondsLeft = seconds - usedSeconds; System.out.println("The number of hh:mm:ss in " + seconds +" is: " + hour + ":" + minutes + ":" + secondsLeft); }
12th Feb 2017, 2:21 PM
Mike Allen
Mike Allen - avatar