Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class _1_Timespan {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- String inputStart = scan.nextLine().trim();
- String inputEnd = scan.nextLine().trim();
- int[] startTimes = readInputLineAndConvertStringToIntegerNums(inputStart);
- int[] endTimes = readInputLineAndConvertStringToIntegerNums(inputEnd);
- int outSec = startTimes[2] - endTimes[2];
- if (outSec < 0) {
- startTimes[1]--;
- outSec += 60;
- }
- int outMin = startTimes[1] - endTimes[1];
- if (outMin < 0) {
- startTimes[0]--;
- outMin += 60;
- }
- int outHour = startTimes[0] - endTimes[0];
- System.out.printf("%d:%02d:%02d%n", outHour, outMin, outSec);
- }
- private static int[] readInputLineAndConvertStringToIntegerNums(
- String inputLine) {
- String[] inputs = inputLine.split(":");
- int[] nums = new int[inputs.length];
- for (int i = 0; i < nums.length; i++) {
- nums[i] = Integer.parseInt(inputs[i]);
- }
- return nums;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement