fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main(String[] args) {
  11. convertTime(3719);
  12. convertTime(3720);
  13. convertTime(3721);
  14. }
  15.  
  16. private static void convertTime(int seconds) {
  17. System.out.println("Time to be converted to hh:mm:ss: " + seconds);
  18. int time = seconds;
  19. int hr = 0, min = 0, sec = 0;
  20. if (time >= 3600) {
  21. hr = time / 3600;
  22. time = time % 3600;
  23. }
  24. if (time >= 60) {
  25. min = time / 60;
  26. time = time % 60;
  27. }
  28. if (time < 60) {
  29. sec += time;
  30. }
  31. System.out.println(hr + ":" + min + ":" + sec);
  32. }
  33. }
Success #stdin #stdout 0.04s 320576KB
stdin
Standard input is empty
stdout
Time to be converted to hh:mm:ss: 3719
1:1:59
Time to be converted to hh:mm:ss: 3720
1:2:0
Time to be converted to hh:mm:ss: 3721
1:2:1