• Create Account

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

2 replies to this topic

### #1Jeffige  Members

113
Like
-1Likes
Like

Posted 10 August 2012 - 07:20 PM

Does anyone know if there are any answers floating around to the exercises in Think Java: Think like a computer scientist by Allen Downey?

I'm stuck on exercise 2.11 - the 24 hour clock.

Thanks for any replies

### #2Jeffige  Members

113
Like
0Likes
Like

Posted 10 August 2012 - 09:39 PM

Any one care to help me understanding this?
I found what is supposed to be the answer but I can't wrap my head around it. Like where did the 3600 come from on this line
seconds_since_midnight = hour * 3600 + minute * 60 + second;

Thanks for any help
[source lang="java"]public class time { public static void main(String[] args) { int hour, minute, second, seconds_since_midnight, seconds_remaining, percentage_passed;hour = 20; minute = 14; second = 29; seconds_since_midnight = hour * 3600 + minute * 60 + second; System.out.print("Seconds since midnight: "); System.out.println(seconds_since_midnight); seconds_remaining = (24 - hour) * 3600 + (60 - minute) * 60 + (60 - second); System.out.print("Seconds remaining in the day: "); System.out.println(seconds_remaining); percentage_passed = seconds_since_midnight * 100 / (3600 * 24); System.out.print("Percentage of the day that has passed: "); System.out.println(percentage_passed); }}[/source]

Edited by Jeffige, 10 August 2012 - 09:46 PM.

### #3RulerOfNothing  Members

1369
Like
2Likes
Like

Posted 10 August 2012 - 09:46 PM

An hour is 60 minutes, and a minute is 60 seconds. You get the 3600 seconds to an hour by simple multiplication.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.