Advertisement
ffpaladin

Angle of the hands of a clock (a quick/first attempt)

Feb 28th, 2014
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1. // By: Sherol
  2. // finding the angle between the hands of a clock
  3.  
  4. public class Clock{
  5.  
  6.      public static void main(String []args){
  7.         System.out.println(getangle(9,45));
  8.      }
  9.      
  10.      public static double getangle(double hour, double min){
  11.          
  12.         // get angle from 12 -> min
  13.         // 360/60 (degrees/min) = 6
  14.         double mindeg = min*6;
  15.         System.out.println(mindeg);
  16.  
  17.      //----------------------------
  18.         // get approx hour angle from 12
  19.         // 360 deg/60 min = 6 deg/min
  20.         double hourdeg = 5 * 6 * (hour%12);
  21.    
  22.         // add offset
  23.         // each hour has (5 min * 6 degrees/min)
  24.         double minratio = min/60;
  25.         System.out.println(minratio);
  26.        
  27.     hourdeg = hourdeg + (30.0 * minratio);
  28.         System.out.println(hourdeg);
  29.  
  30.         //----------------------------
  31.         return (mindeg-hourdeg) % 360 ;
  32.      }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement