View Code of Problem 56

import java.util.Scanner;
 
 
public class Main 
{
    public static void main(String[] args) 
    {
        Scanner scan = new Scanner(System.in);
      String str1=scan.nextLine();
       String str2=scan.nextLine();
      String[] s1=str1.split(":");
      String[] s2=str2.split(":");
      int t1=Integer.parseInt(s1[0])*3600+Integer.parseInt(s1[1])*60+Integer.parseInt(s1[2]);
      int t2=Integer.parseInt(s2[0])*3600+Integer.parseInt(s2[1])*60+Integer.parseInt(s2[2]);
      double k=Math.abs(t1-t2);
      int a=(int)(k/3600);
      int b=(int)((k%3600)/60);
      int c=(int)((k%3600)%60);
      System.out.println(String.format("%d:%02d:%02d",a,b,c));
      
      
    }
}

Double click to view unformatted code.


Back to problem 56