import java.util.Scanner;
import java.util.Arrays;
public class Main
{
    public static void main(String[] args) {
        double hours;
        double mins;
        clock c;
//do {
Scanner reader = new Scanner(System.in); // Reading from System.in
System.out.println("Enter a number between 0-23 to denote HH   in  HH:mm 24 hour clock");
hours = reader.nextInt(); // Scans the next token of the input as an int.
System.out.println("Enter a number between 0-59 to denote MM   in  hh:MM 24 hour clock");
mins = reader.nextInt(); // Scans the next token of the input as an int.
//once finished
reader.close();


System.out.println("\n");
// THE FUNCTION HAS TO START here

c= new clock(hours,mins);
}

}


class clock
{
    double hours; //counter
    double mins; //counter
    double degrees;
    double hr24Tohr12;
    double angleHour;
    double angleMinute;
    
    double angleH;
    double angleM;
    
    
public clock(double hours, double mins)
{
    this.hours=hours;
    this.mins=mins;
    double temp;
    double Angle;
    
    if (hours>12)                           //conversion from hh:mm  to  h:mm
    {
        hours=hours-12;
        
    }
    
    System.out.println("This is hours: " + hours);
    System.out.println("This is mins: " + mins);
    
    if (hours==12)                 //ensure  any loops can execute from 0:00  to  11:59 in forthcoming code
    {
        hours=0;
    }
    
    angleMinute = (mins/60)*360;
    angleHour  = ((hours/12)*360) + ((angleMinute/360)*30);
    
    
    System.out.println("Angle of minute hand from 12 o'clock: " + angleMinute);
    System.out.println("Angle of hour hand from 12 o'clock: " + angleHour);
    
    Angle = Math.round(Math.abs(angleHour-angleMinute));
   
// This is to ensure that hands can not be further than 6 o’clock apart
    if ((angleHour-angleMinute)>180)
    {
        Angle = 360 - Math.round(Math.abs(angleHour-angleMinute));
        
    }
    
    System.out.println("Angle is:  " +  Angle);
        
    // This is now checking if there are any moments when angle between minute and hour hand is ZERO 
    
        double hrs;
        double minutes;
        double seconds;
        int z=0;
    
        for (int i=0;i<12;i++)
        {
            for (int j=0;j<60;j++)
            {
                for (int k=0;k<60;k++)
                {
                hrs=i;
                minutes=j;
                seconds=k;
                z++;
               
                
                
                //each minute is 1/60th of the clock (6 degrees)
                //position of minute hand is influenced by second hand also.
                angleM = (minutes/60)*360 +  ((seconds/60/60)*360);
                
                //each hour is 1/12th of the clock (30 degrees)
                //position hour hand is influenced by minute and second hand
                angleH = ((hrs/12)*360) + ((minutes/60/12)*360) + ((seconds/60/60/12)*360);
                
                System.out.println("Hours is: " + hrs + ": " + angleH);
                System.out.println("Minutes is: " + minutes + ": " + angleM);
                System.out.println("Seconds is: " + seconds);
                System.out.println("\n");
                
                
                temp=angleH-angleM;
                
                if (Math.abs(temp)>180)
                {
                temp = 360 - temp;
                }
                
                
                if (Math.abs(temp)==0)
                {
                    System.out.println("Hours and minute hand coincides:");
                    System.out.println("hours: " + hrs);
                    System.out.println("mins:" + minutes);
                    System.out.println("seconds:" + seconds);
                    break;
                    
                    
                }
                
                
                
                
                
                }
            }
            
            
            
        
        }
    
    
}

}
