View Code of Problem 56

import java.util.Scanner;

public class Main
{
  public static void main(String[] args)
  {
    Scanner scan=new Scanner(System.in);
    int h=scan.nextInt();
    int m=scan.nextInt();
    int s=scan.nextInt();
    int hh=scan.nextInt();
    int mm=scan.nextInt();
    int ss=scan.nextInt();
    
    int t1=h*3600+m*60+s;
    int t2=hh*3600+mm*60+ss;
    int t=t1>t2?t1-t2:t2-t1;
    
    int h1=t/3600;
    int m1=(t%3600)/60;
    int s1=t%60;
    
    System.out.println(String.format("%d:%02d:%02d",h1,m1,s1));
    
  }
}

Double click to view unformatted code.


Back to problem 56