desislava_topuzakova

01. Сумиране на секунди

Oct 31st, 2021
975
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. package CodnitionalStatements;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class SumSeconds_01 {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         int firstTime = Integer.parseInt(scanner.nextLine());
  9.         int secondTime = Integer.parseInt(scanner.nextLine());
  10.         int thirdTime = Integer.parseInt(scanner.nextLine());
  11.  
  12.         //намираме сумата от времената на тримата -> секунди
  13.         int sumInSeconds = firstTime + secondTime + thirdTime;
  14.  
  15.         //преобразувам сумата от секунди -> минути и секунди
  16.         int minutes = sumInSeconds / 60;
  17.         int seconds = sumInSeconds % 60;
  18.  
  19.         //печатаме
  20.         //секунди < 10 -> минути:0секунди
  21.         //секунди >= 10 -> минути:секунди
  22.         if (seconds < 10) {
  23.             System.out.printf("%d:0%d", minutes, seconds);
  24.         } else { //seconds >= 10
  25.             System.out.printf("%d:%d", minutes, seconds);
  26.         }
  27.     }
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment