579 - ClockHands

Problem Link

import java.util.*;
import java.text.*;
public class uva579 {
public static void main(String [] args) {
Scanner scn = new Scanner (System.in);
String ls = System.getProperty("line.separator");
scn.useDelimiter(ls);
DecimalFormat df = new DecimalFormat("0.000");
double h = 1.0, m = 1.0;
String hm = scn.next();
StringTokenizer st = new StringTokenizer(hm,":");
h = Double.parseDouble((String)st.nextElement());
m = Double.parseDouble((String)st.nextElement());
while(h != 0) {
if(h == 12 && m == 0)
System.out.println("0.000");
else if(h == 6 && m == 0)
System.out.println("180.000");
else {
double j = m*6;// 180deg/30saat=6deg/saat
double tm = (m/60) + h;
h = tm*30-j;
double noneg = Math.abs(h);//elakkan jawapan negatif
if(noneg > 180)
noneg = 360-noneg;
System.out.println(df.format(noneg));
}
hm = scn.next();
st = new StringTokenizer(hm,":");
h = Integer.parseInt((String)st.nextElement());
m = Integer.parseInt((String)st.nextElement());
}
}
}

Share this

Related Posts

Previous
Next Post »