Advertisement
nmnikolov

JavaExam21Sep_01_Timespan

Sep 22nd, 2014
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class Exam21Sep14_01_Timespan {
  5.  
  6.     public static void main(String[] args) {
  7.         Scanner input = new Scanner(System.in);
  8.        
  9.         String[] end = input.nextLine().split(":");
  10.         String[] start = input.nextLine().split(":");
  11.        
  12.         long endTime = Long.parseLong(end[2]) + Long.parseLong(end[1]) * 60 + Long.parseLong(end[0]) * 3600;
  13.         long startTime = Long.parseLong(start[2]) + Long.parseLong(start[1]) * 60 + Long.parseLong(start[0]) * 3600;
  14.        
  15.         long timeSpan = endTime - startTime;
  16.        
  17.         long hours = timeSpan / 3600;
  18.         long minutes = (timeSpan % 3600) / 60;
  19.         long seconds = (timeSpan % 3600) % 60;
  20.        
  21.         System.out.printf("%d:%02d:%02d", hours, minutes, seconds);
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement