I found some major bugs in my code and also in 200_success's code200_success's code. Since bug-determining and killing also a part of code-review I want to post this as an answer not as a comment. I think it's OK? right?
Input Correct output My output 200_success's output [No bugs found] 12:01 am 11:59 pm 00:59 pm x 11:59 pm 11:32 am 12:28 pm 00:28 pm x 12:28 pm 12:34 am 11:26 pm -1:26 pm x 11:26 pm 06:01 am 05:59 pm 06:59 pm x 05:59 pm 11:02 am 12:58 pm 01:58 pm x 12:58 pm 12:59 am 11:01 pm -1:1 pm x 11:01 pm
x
is marked as wrong output.
So in my code the line
if(minuteAsInt < 12) {
return (12 - hourAsInt) + "";
}
is making all kind of troubles. When I wrote the code, I made a theoretical assumption which doesn't stand in practical usage. What I thought was that
If the hour hand travels 30° in 60 minutes, then it will travel 6° in 12 minutes. So after XX:12
the hour hand will move.
But in practical cases we assume that hour hand moves continuously after XX:00
.
Also there are corner cases for 12:XX
and 11:XX
. As 12 - hourAsInt - 1
will give -ve
or 00:XX
value respectively.