Advertisement
Spocoman

Exam Schedule

Sep 5th, 2024
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int hours = Integer.parseInt(scanner.nextLine()),
  7.                 minutes = Integer.parseInt(scanner.nextLine());
  8.         String dayPart = scanner.nextLine();
  9.         int hoursAdded = Integer.parseInt(scanner.nextLine()),
  10.                 minutesAdded = Integer.parseInt(scanner.nextLine()),
  11.                 result = (hours + hoursAdded) * 60 + minutes + minutesAdded,
  12.                 totalHours = result / 60 % 24, totalMinutes = result % 60;
  13.  
  14.         dayPart = totalHours >= 12 ? (dayPart.equals("AM") ? "PM" : "AM") : dayPart;
  15.         totalHours -= totalHours > 12 ? 12 : 0;
  16.  
  17.         System.out.printf("%02d:%02d:%s\n", totalHours, totalMinutes, dayPart);
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement