Advertisement
myrdok123

04. Time After 30 Minutes

May 15th, 2024
685
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.65 KB | None | 0 0
  1. package ProgramingBasicsOverview;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P04_TimeAfter30Minutes {
  6.  
  7.     public static void main(String[] args) {
  8.  
  9.         Scanner scanner = new Scanner(System.in);
  10.  
  11.         int hour = Integer.parseInt(scanner.nextLine());
  12.         int minutes = Integer.parseInt(scanner.nextLine());
  13.  
  14.         int totalMinutesPlus30Minutes = hour * 60 + minutes + 30;
  15.  
  16.         int finalHours = totalMinutesPlus30Minutes / 60;
  17.         int finalMinutes = totalMinutesPlus30Minutes % 60;
  18.  
  19.         if(finalHours > 23){
  20.             finalHours = 0;
  21.         }
  22.  
  23.         System.out.printf("%d:%02d", finalHours, finalMinutes);
  24.     }
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement