Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int hours = Integer.parseInt(scanner.nextLine()),
- minutes = Integer.parseInt(scanner.nextLine());
- String dayPart = scanner.nextLine();
- int hoursAdded = Integer.parseInt(scanner.nextLine()),
- minutesAdded = Integer.parseInt(scanner.nextLine()),
- result = (hours + hoursAdded) * 60 + minutes + minutesAdded,
- totalHours = result / 60 % 24, totalMinutes = result % 60;
- dayPart = totalHours >= 12 ? (dayPart.equals("AM") ? "PM" : "AM") : dayPart;
- totalHours -= totalHours > 12 ? 12 : 0;
- System.out.printf("%02d:%02d:%s\n", totalHours, totalMinutes, dayPart);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement