Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class ExamSchedule {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int startHour = scan.nextInt();
- int startMins = scan.nextInt();
- String partOfDay = scan.next();
- int durationHours = scan.nextInt();
- int durationMins = scan.nextInt();
- int endHour = startHour + durationHours;
- int endMins = startMins + durationMins;
- switch (partOfDay) {
- case "PM":
- if (endMins > 59) {
- endMins = endMins % 60;
- endHour ++;
- }
- if (endHour >= 12) {
- endHour = endHour % 12;
- if (endHour == 0 || endHour == 24) {
- endHour = 12;
- }
- partOfDay = "AM";
- }
- break;
- case "AM":
- if (endMins > 59) {
- endMins = endMins % 60;
- endHour++;
- }
- if (endHour >= 12) {
- endHour = endHour % 12;
- if (endHour == 0 || endHour == 24) {
- endHour = 12;
- }
- partOfDay = "PM";
- }
- }
- System.out.printf("%02d:%02d:%s", endHour, endMins, partOfDay);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement