Advertisement
Samorokimetal

Sum Seconds

Apr 6th, 2020
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Sportisti {
  4.     public static void main(String[] args) {
  5.        
  6.         Scanner scan = new Scanner(System.in); 
  7.        
  8.         System.out.print("Vreme na sustezatel 1: ");
  9.         int sustezatel1 = Integer.parseInt(scan.nextLine());
  10.         proverka(sustezatel1);
  11.        
  12.        
  13.         System.out.print("Vreme na sustezatel 2: ");
  14.         int sustezatel2 = Integer.parseInt(scan.nextLine());
  15.         proverka(sustezatel2);
  16.        
  17.         System.out.print("Vreme na sustezatel 3: ");
  18.         int sustezatel3 = Integer.parseInt(scan.nextLine());
  19.         proverka(sustezatel3);
  20.        
  21.         scan.close();
  22.         System.out.println();
  23.        
  24.         int sum = sustezatel1 + sustezatel2 + sustezatel3;
  25.         int minutes = Math.abs(sum / 60);
  26.         int seconds = Math.abs(sum % 60);
  27.        
  28.         System.out.printf("Total time: %d:%02d", minutes, seconds);
  29.        
  30.     }
  31.     public static void proverka(int vreme) {
  32.         if (!(vreme > 0 && vreme <= 50)) {
  33.             System.out.println();
  34.             System.out.print("Invalid time");
  35.             System.exit(0);
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement