I am trying to make a time calculator. (Made a post about it earlier, and I fixed it). The code is working as intended, except when I enter the number 500,000. It just automatically terminates the program with no print statement. However I can enter anything from 1 - 488888 and 544444 - 900000 if I wished and it would work.
I've moved my if-statements around, nested a few here and there. I can't gauge where the problem rises in the if/else if statements.
final int x = 9;
final int y = 1;
final int Days;
final int Hours;
final int Minutes;
final int Seconds;
Days = total_seconds / 86400;
Hours = (total_seconds % 86400 ) / 3600;
Minutes = ((total_seconds % 86400 ) % 3600 ) / 60;
Seconds = ((total_seconds % 86400 ) % 3600 ) % 60;
if (Hours == 0) {
if (Minutes < x || Seconds < x) {
String padded = String.format("%02d" , Minutes);
String padded2 = String.format("%02d" , Seconds);
System.out.print("You entered " + total_seconds + " second(s), which is " + Minutes + " minute(s), and " + Seconds + " second(s).");
System.out.print("\n");
System.out.print(padded + ":" + padded2);
}
}
else if (Hours >= y && Days == 0) {
if (Minutes < x || Seconds < x) {
String padded = String.format("%02d" , Minutes);
String padded2 = String.format("%02d" , Seconds);
System.out.print("You entered " + total_seconds + " second(s), which is " + Hours + " hour(s), " + Minutes + " minute(s), and " + Seconds + " second(s).");
System.out.print("\n");
System.out.print(Hours + ":" + padded + ":" + padded2 + " hours.");
}
}
else if (Days >= y && Hours >= y) {
if (Minutes < x || Seconds < x) {
String padded = String.format("%02d" , Minutes);
String padded2 = String.format("%02d" , Seconds);
System.out.print("You entered " + total_seconds + " second(s), which is " +
Days + " day(s), " + Hours + " hour(s), " + padded + " minute(s), and " +
padded2 + " second(s).");
System.out.print("\n");
System.out.print(Days + " day(s) " + Hours + ":" + padded + ":" + padded2 +
" hour(s).");
}
}
else {
System.out.print("You entered " + total_seconds + " second(s), which is " + Days + " day(s), " + Hours + " hour(s), " + Minutes + " minute(s), and " + Seconds + " second(s).");
System.out.print("\n");
System.out.print(Days + " day(s) " + Hours + ":" + Minutes + ":" + Seconds + " hour(s).");
}
When I enter any number that has a number of Days, it should output:
"You entered 500,000 seconds, which is 5 days, 18 hours, 53 minutes, and 20 seconds. (5 days 18:53:20 hours)"
The actual output (when I input 500,000) is absolutely nothing. The program just auto terminates with no print.
I have added else
, but problem persists.