Advertisement
Razhagal

Video Duration

Jun 1st, 2014
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class VideoDurations {
  5.  
  6.     public static void main(String[] args) {
  7.         Scanner input = new Scanner(System.in);
  8.        
  9.         String videoLenght = "";
  10.         int hoursLenght = 0;
  11.         int minutesLenght = 0;
  12.         int hoursSum = 0;
  13.         int minutesSum = 0;
  14.        
  15.         while (true) {
  16.             videoLenght = input.nextLine();
  17.            
  18.             if (videoLenght.equals("End")) {
  19.                 break;
  20.             }
  21.            
  22.             String[] times = videoLenght.split(":");
  23.             hoursLenght = Integer.parseInt(times[0]);
  24.             minutesLenght = Integer.parseInt(times[1]);
  25.            
  26.             hoursSum += hoursLenght;
  27.             minutesSum += minutesLenght;
  28.            
  29.             if (minutesSum >= 60) {
  30.                 hoursSum += 1;
  31.                 minutesSum -= 60;
  32.             }
  33.            
  34.         }
  35.        
  36.         String mins = String.format("%2d", minutesSum).replace(' ', '0');
  37.        
  38.         System.out.printf("%d:%s",hoursSum, mins);
  39.     }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement