Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Timespan {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String[] start = sc.nextLine().split(":");
- String[] end = sc.nextLine().split(":");
- int startHours = Integer.parseInt(start[0]);
- int startMinutes = Integer.parseInt(start[1]);
- int startSeconds = Integer.parseInt(start[2]);
- int endHours = Integer.parseInt(end[0]);
- int endMinutes = Integer.parseInt(end[1]);
- int endSeconds = Integer.parseInt(end[2]);
- int timespan = 0;
- int hours = startHours - endHours;
- int minutes = startMinutes - endMinutes;
- int seconds = startSeconds - endSeconds;
- if (seconds < 0) {
- seconds = 60 + seconds;
- minutes--;
- }
- if (minutes < 0) {
- minutes = 60 + minutes;
- hours--;
- }
- System.out.printf("%d:%02d:%02d", hours, minutes, seconds);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement