svephoto

Time + 15 Minutes [Java]

Apr 15th, 2021 (edited)
442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class TimePlus15Minutes {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int hour = Integer.parseInt(scanner.nextLine());
  8.         int minutes = Integer.parseInt(scanner.nextLine());
  9.  
  10.         int allMinutes = hour * 60 + minutes + 15;
  11.         int hours = allMinutes / 60;
  12.         int newMinutes = allMinutes % 60;
  13.  
  14.         if (hours == 24) {
  15.             hours = 0;
  16.         }
  17.  
  18.         if (newMinutes < 10) {
  19.             System.out.printf("%d:%02d%n", hours, newMinutes);
  20.         } else {
  21.             System.out.printf("%d:%d%n", hours, newMinutes);
  22.         }
  23.     }
  24. }
  25.  
Add Comment
Please, Sign In to add comment