Advertisement
Venciity

Java exam - 01.VideoDurations

Jun 3rd, 2014
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.67 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class _01_VideoDurations {
  5.  
  6.     public static void main(String[] args) {
  7.         @SuppressWarnings("resource")
  8.         Scanner input = new Scanner(System.in);
  9.         String duration = input.nextLine();
  10.        
  11.         int mins = 0;
  12.         int hours = 0;
  13.        
  14.         while (!duration.equals("End")) {
  15.             String[] split = duration.split(":");
  16.             int getHours = Integer.valueOf(split[0]);
  17.             int getMinutes = Integer.valueOf(split[1]);
  18.             mins += getMinutes;
  19.             hours +=  getHours;
  20.            
  21.             if (mins > 59) {
  22.                 hours++;
  23.                 mins -=60;
  24.             }
  25.             duration = input.nextLine();
  26.         }
  27.         System.out.print(hours);
  28.         System.out.print(":");
  29.         System.out.printf("%02d" , mins);
  30.     }
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement