## Epic Systems Interview Question

Software Engineer / Developers**Country:**United States

```
public class clock_angle {
public static void main(String args[])
{
System.out.println("angle swapped:> "+calculate("02:23"));
System.out.println("angle swapped:> "+calculate("03:15"));
System.out.println("angle swapped:> "+calculate("03:30"));
}
static Integer calculate(String time)
{ int angle = 0;
int degree_min=360/60;
int degree_hour=360/12;
String str=time+"";
String a=str.substring(0,2);
String b=str.substring(3,5);
int i = Integer.parseInt(a.substring(0));
int j = Integer.parseInt(b.substring(0));
int hour_degree_swapped=i*degree_hour;
int min_degree_swapped=j*degree_min;
if(hour_degree_swapped>min_degree_swapped)
{
angle=hour_degree_swapped-min_degree_swapped;
}
else if(hour_degree_swapped<min_degree_swapped)
{
angle=min_degree_swapped-hour_degree_swapped;
}
else if(hour_degree_swapped==min_degree_swapped)
{angle=0;
}
return angle;
}
}
```

// please see modified solution of above solution for accurate answer

```
public class clock_angle {
public static void main(String args[])
{
System.out.println("angle swapped:> "+calculate("02:23"));
System.out.println("angle swapped:> "+calculate("03:15"));
System.out.println("angle swapped:> "+calculate("03:30"));
}
static Integer calculate(String time)
{ int angle = 0;
int degree_min=360/60;
int degree_hour=360/12;
String str=time+"";
String a=str.substring(0,2);
String b=str.substring(3,5);
int i = Integer.parseInt(a.substring(0));
int j = Integer.parseInt(b.substring(0));
int hour_degree_swapped=(i*degree_hour)+(degree_hour*j/60);
int min_degree_swapped=j*degree_min;
angle=Math.abs(hour_degree_swapped-min_degree_swapped);
return angle;
}
}
```

```
'''
Get the angle between hour and minute hands, given time
Angle must be < 180
'''
def get_angle(hh, mm):
mm = float(mm)
hh_angle_from_zero = (hh + (mm / 60)) * 30
mm_angle_from_zero = mm * 6 # which is short form for -> mm/60 * 360
diff = abs(hh_angle_from_zero - mm_angle_from_zero) % 180
return diff
print (get_angle(0,0)) # 0
print (get_angle(2,30)) # 105
print (get_angle(6,30)) # 15
print (get_angle(11,30)) # 165
```

- AI October 21, 2014