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 timeExam = Integer.parseInt(scanner.nextLine());
- int minuteExam = Integer.parseInt(scanner.nextLine());
- int timeArrival = Integer.parseInt(scanner.nextLine());
- int minuteArrival = Integer.parseInt(scanner.nextLine());
- int Exam = timeExam * 60 + minuteExam;
- int Arrival = timeArrival * 60 + minuteArrival;
- int difference1 = Exam - Arrival;
- int difference2 = Arrival - Exam;
- if (difference1 > 0 && difference1 <= 30) {
- System.out.printf("On time %n%d minutes before the start", difference1);
- } else if (difference1 > 30 && difference1 <= 59) {
- System.out.printf("Early %n%d minutes before the start", difference1);
- } else if (difference1 > 59) {
- int hh = difference1 / 60;
- int mm = difference1 % 60;
- System.out.printf("Early %n%d:%02d hours before the start", hh, mm);
- }else {
- System.out.println("On time");
- }
- if (difference2 > 0 && difference2 <= 59) {
- System.out.printf("Late %n %d minutes after the start", difference2);
- } else if (difference2 > 59) {
- int hh = difference2 / 60;
- int mm = difference2 % 60;
- System.out.printf("Late %n%d:%02d hours after the start", hh, mm);
- }
- }
- }
Add Comment
Please, Sign In to add comment