Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class OnTimeForTheExam_09 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int examHours = Integer.parseInt(scanner.nextLine());
- int examMinute = Integer.parseInt(scanner.nextLine());
- int arrivalHours = Integer.parseInt(scanner.nextLine());
- int arrivalMinute = Integer.parseInt(scanner.nextLine());
- int timeExam =Math.abs(examHours * 60) + examMinute;
- int timeArrival =Math.abs(arrivalHours * 60) + arrivalMinute;
- if (timeArrival > timeExam) {
- int timeLate = timeArrival - timeExam;
- if (timeLate < 60) {
- int lateMinutes = timeLate % 60;
- System.out.println("Late");
- System.out.printf("%d minutes after the start", lateMinutes);
- }
- else if (timeLate >= 60) {
- int lateHours = timeLate / 60;
- int lateMinutes = timeLate % 60;
- System.out.println("Late");
- System.out.printf("%d:%02d hours after the start", lateHours, lateMinutes);
- }
- }
- else if (timeArrival < timeExam) {
- int timeEarly = timeExam - timeArrival;
- if (timeEarly > 30 && timeEarly < 60) {
- int earlyMinutes = timeEarly % 60;
- System.out.println("Early");
- System.out.printf("%d minutes before the start", earlyMinutes);
- } else if (timeEarly >= 60) {
- int earlyHours = timeEarly / 60;
- int earlyMinutes = timeEarly % 60;
- System.out.println("Early");
- System.out.printf("%d:%02d hours before the start", earlyHours, earlyMinutes);
- } else if (timeEarly <= 30){
- System.out.println("On time");
- System.out.printf("%d minutes before the start", timeEarly);
- }
- } else {
- System.out.println("On time");
- }
- }
- }
Add Comment
Please, Sign In to add comment