-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprob18.java
More file actions
34 lines (31 loc) · 1.09 KB
/
Copy pathprob18.java
File metadata and controls
34 lines (31 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import java.io.File;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.Scanner;
public class prob18 {
public static void main(String[] args) throws IOException {
DecimalFormat df = new DecimalFormat("######0.00");
Scanner in = new Scanner(new File("input.txt"));
String line;
int hour, mins;
double hourDeg, minDeg, degree;
while(in.hasNext()){
line = in.nextLine();
Scanner input = new Scanner(new String(line));
input.useDelimiter(":");
hour = input.nextInt();
if(hour>=12)
hour-=12;
mins = input.nextInt();
hourDeg = hour*30.0 + mins/2.0;
minDeg = mins*6.0;
degree = hourDeg - minDeg;
if(degree<0)
degree*=-1;
if(degree>180)
degree = 360-degree;
String ans = df.format(degree);
System.out.println("The angle between the Hour hand and Minute hand is " + ans + " degrees.");
}
}
}