码迷,mamicode.com
首页 > 其他好文 > 详细

Clock Angle

时间:2014-11-21 10:36:27      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   ar   color   os   sp   strong   on   

Problem

We are given a specific time(like 02:23), we need to get the angle between hour and minute(less than 180)

Solution

 1 public static double clockAngle(String time) {
 2     if(time == null)    return -1;
 3     double angle = 0;
 4     
 5     int hour = 0, minute = 0;
 6     String[] hm = new String[2];
 7     hm = time.split(":");
 8     System.out.println(Arrays.toString(hm));
 9     
10     hour = Integer.parseInt(hm[0]);
11     minute = Integer.parseInt(hm[1]);
12     
13     doubleminAngle = minute*6;
14     double hourAngle = hour*30 + minAngle/12;
15     angle = Math.abs(minAngle - hourAngle);
16     if(angle > 180) angle = 360 - angle;
17     
18     return angle;
19 }

 

Clock Angle

标签:style   blog   io   ar   color   os   sp   strong   on   

原文地址:http://www.cnblogs.com/superbo/p/4112081.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!