Created
December 30, 2016 22:59
-
-
Save dharmakshetri/127a8b935ee27f68bcd22eae28c9afad to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* package whatever; // don't place package name! */ | |
import java.util.*; | |
import java.lang.*; | |
import java.io.*; | |
/* Name of the class has to be "Main" only if the class is public. */ | |
class Ideone | |
{ | |
public static void main (String[] args) throws java.lang.Exception | |
{ | |
// your code goes here | |
System.out.println("Difference Angle: " + calculateAngle(3.00, 30.00)); | |
} | |
public static int calculateAngle(double h, double m){ | |
// check the all input validation | |
if(h<0 || h>12 || m<0 || m>60) | |
System.out.println("Please provide correct inputs"); | |
// both hour and minutes in same point | |
if(h==12) h=0; | |
if(m==60) m=0; | |
int hourAngle=(int)(h*60+m)/2; | |
int minuteAngle=(int)(6*m); | |
int angle=Math.abs(hourAngle-minuteAngle); | |
angle=min(360-angle, angle); | |
return angle; | |
} | |
public static int min(int x, int y){ | |
return (x<y)? x:y; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment