Advertisement
desislava_topuzakova

05. Time + 15 Minutes

Oct 11th, 2020
2,068
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class TimePlus15Minutes_05 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         //1. прочитаме час и минутите
  7.         //2. преобразуваме времето от часове и минути в минути
  8.         //3. добавим 15 минути
  9.         //4. преобразуваме в часове и минути
  10.         //5. печатаме
  11.  
  12.         int currentHours = Integer.parseInt(scanner.nextLine());
  13.         int currentMinutes = Integer.parseInt(scanner.nextLine());
  14.  
  15.         int currentTimeInMinutes = currentHours * 60 + currentMinutes;
  16.         int timePlus15Minutes = currentTimeInMinutes + 15;
  17.  
  18.         int finalHour = timePlus15Minutes / 60;
  19.         int finalMinutes = timePlus15Minutes % 60;
  20.  
  21.         if (finalHour == 24) {
  22.             finalHour = 0;
  23.         }
  24.         //часове:минути
  25.         System.out.printf("%d:%02d", finalHour, finalMinutes);
  26.  
  27.  
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement