File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programming Diversions and the fly likes [Easy]find the angles between the hands Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Other » Programming Diversions
Bookmark "[Easy]find the angles between the hands" Watch "[Easy]find the angles between the hands" New topic
Author

[Easy]find the angles between the hands

Arjun Shastry
Ranch Hand

Joined: Mar 13, 2003
Posts: 1874
I have taken this from one of the competition.I have sloved this ,wanted to check in how many ways this can be done.
Write a program: Given a time,return the angles between the hands of the clock.[first is hour hand to minute ,minute to second,second to hour]
Return values should be of type 'float'.
Example
0)12:00:00
returns: 0,0,0
1)9:30:00
returns 105,180,75


MH
HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
It could be me, but I think there is some discrepancy here.
Is the angle between the hands measured clockwise? In which case :-
12:00:00 and 00:00:00 should have the same angle readings. I am just not sure that it is 0 0 0.
How should the program handle 24 hours ?
regards
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11161
    
  16

you can calculate each hand's position based on the time.
the second hand is at 360 * (seconds / 60) degrees
the minute hand is at 360 * (minutes * 60 + seconds) / 3600
the hour hand... whatever
then, once you know the position of each individual hand, you can just subtract... and maybe take the absolute value....
this is just off the top of my head, so i haven't worked out all (well, any) of the details, so forgive me if anything isn't exactly right...
f


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
jQuery in Action, 2nd edition
 
subject: [Easy]find the angles between the hands
 
Similar Threads
What fields does java.util.Date.equals compare?
How to convert hours,minutes,seconds to seconds
Java help!!!!
question about how to convet the "date" to milliseconds
java.util.Date does it contain information about hours?