Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class OnTimeForTheExam {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int examHour = Integer.parseInt(scanner.nextLine());
- int examMinutes = Integer.parseInt(scanner.nextLine());
- int arrivalHour = Integer.parseInt(scanner.nextLine());
- int arrivalMinutes = Integer.parseInt(scanner.nextLine());
- int examTimeInMins = (examHour * 60) + examMinutes;
- int arrivalTimeInMins = (arrivalHour * 60) + arrivalMinutes;
- int diff = examTimeInMins - arrivalTimeInMins;
- int hour = Math.abs(diff / 60);
- int mins = Math.abs(diff % 60);
- if (diff < 0) {
- System.out.println("Late");
- if (Math.abs(diff) >= 60) {
- if (mins < 10) {
- System.out.printf("%d:%0d hours after the start", hour, mins);
- } else {
- System.out.printf("%d:%d hours after the start", hour, mins);
- }
- } else {
- System.out.printf("%d minutes after the start", mins);
- }
- } else if (diff >= 0 && diff <= 30) {
- if (diff == 0) {
- System.out.println("On time");
- } else {
- System.out.println("On time");
- System.out.printf("%d minutes before the start", mins);
- }
- } else {
- System.out.println("Early");
- if (Math.abs(diff) >= 60) {
- if (mins < 10) {
- System.out.printf("%d:%0d hours before the start", hour, mins);
- } else {
- System.out.printf("%d:%d hours before the start", hour, mins);
- }
- } else {
- System.out.printf("%d minutes before the start", mins);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement