SHARE
TWEET

05.Time + 15 Minutes

a guest Feb 16th, 2020 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top