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 examMin = Integer.parseInt(scanner.nextLine());
- int arriveHour = Integer.parseInt(scanner.nextLine());
- int arriveMin = Integer.parseInt(scanner.nextLine());
- int differenceTotalMin = (arriveHour * 60 + arriveMin) - (examHour * 60 + examMin);
- int differenceHours = Math.abs(differenceTotalMin / 60);
- int differenceMin = Math.abs(differenceTotalMin % 60);
- if (differenceTotalMin > 0) {
- System.out.println("Late");
- } else if (differenceTotalMin >= -30) {
- System.out.println("On time");
- } else {
- System.out.println("Early");
- }
- if (differenceTotalMin >= 60) {
- System.out.printf("%d:%02d hours after the start", differenceHours, differenceMin);
- } else if (differenceTotalMin > 0) {
- System.out.printf("%d minutes after the start", differenceMin);
- }
- if (differenceTotalMin <= -60) {
- System.out.printf("%d:%02d hours before the start", differenceHours, differenceMin);
- } else if (differenceTotalMin < 0) {
- System.out.printf("%d minutes before the start", differenceMin);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment