+ 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
2 Answers
+ 1
Little hint:
You could simply use div and mod ( / and % ) to solve the problem. What do you have got so far?
+ 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);
}