myrdok123

03. Time + 15 Minutes

Apr 30th, 2023
980
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.06 KB | None | 0 0
  1. package L02_ConditionalStatements;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P03_TimePlus15Minutes {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.  
  10.         // Прочитаме входните данни
  11.         // Превръщаме всичко в минути
  12.         // Пресмятаме часовете и минутите, след като добавим 15 минути
  13.         // Проверим колко са часовете -> ако са 24 трябва да ги направим 0
  14.  
  15.         int hours = Integer.parseInt(scanner.nextLine());
  16.         int minutes = Integer.parseInt(scanner.nextLine());
  17.  
  18.         int totalMinutes = hours * 60 + minutes + 15;
  19.  
  20.         int finalHours = totalMinutes / 60;
  21.         int finalMinutes = totalMinutes % 60;
  22.  
  23.         if (finalHours >= 24){
  24.             finalHours = 0;
  25.             System.out.printf("%d:%02d", finalHours, finalMinutes);
  26.         } else {
  27.             System.out.printf("%d:%02d", finalHours, finalMinutes);
  28.         }
  29.  
  30.     }
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment