Advertisement
nedjo

Timespan

Sep 22nd, 2014
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.85 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Timespan {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner sc = new Scanner(System.in);
  7.         String[] start = sc.nextLine().split(":");
  8.         String[] end = sc.nextLine().split(":");
  9.         int startHours = Integer.parseInt(start[0]);
  10.         int startMinutes = Integer.parseInt(start[1]);
  11.         int startSeconds = Integer.parseInt(start[2]);
  12.         int endHours = Integer.parseInt(end[0]);
  13.         int endMinutes = Integer.parseInt(end[1]);
  14.         int endSeconds = Integer.parseInt(end[2]);
  15.         int timespan = 0;
  16.         int hours = startHours - endHours;
  17.         int minutes = startMinutes - endMinutes;
  18.         int seconds = startSeconds - endSeconds;
  19.         if (seconds < 0) {
  20.             seconds = 60 + seconds;
  21.             minutes--;
  22.         }
  23.         if (minutes < 0) {
  24.             minutes = 60 + minutes;
  25.             hours--;
  26.         }
  27.         System.out.printf("%d:%02d:%02d", hours, minutes, seconds);
  28.     }
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement