Advertisement
Guest User

05.Time + 15 Minutes

a guest
Feb 16th, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class TimeAfter15Minutes_05 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         //read hour, minutes
  7.         int hour = Integer.parseInt(scanner.nextLine()); //23
  8.         int minutes = Integer.parseInt(scanner.nextLine()); //59
  9.         //calculate total in minutes = hour * 60 + minutes
  10.         int totalInMinutes = hour * 60 + minutes; // 1439
  11.         int totalInMinutesPlus15 = totalInMinutes + 15; //1439 + 15 = 1454
  12.  
  13.         //calculate endHour = totalAfter15 / 60
  14.         //calculate endMinute = totalAfter % 60
  15.  
  16.         int endHour = totalInMinutesPlus15 / 60; //24
  17.         int endMinutes = totalInMinutesPlus15 % 60; //14
  18.  
  19.         if(endHour == 24){
  20.            endHour = 0;
  21.         }
  22.  
  23.         //print hour:minute
  24.         System.out.printf("%d:%02d",endHour, endMinutes);
  25.  
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement