Advertisement
MiniMi2022

On time for the exam

Mar 27th, 2023
625
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.06 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class OnTimeForTheExam {
  4.     public static void main(String[] args) {
  5.         Scanner myScan = new Scanner(System.in);
  6.         int hourExam = Integer.parseInt(myScan.nextLine());
  7.         int minutesExam = Integer.parseInt(myScan.nextLine());
  8.         int hourArrival = Integer.parseInt(myScan.nextLine());
  9.         int minutesArrival = Integer.parseInt(myScan.nextLine());
  10.         int timeExam=hourExam*60+minutesExam;
  11.         int timeArrival=hourArrival*60+minutesArrival;
  12.         int diff=timeExam-timeArrival;
  13.         String text="before";
  14.         if (diff<0){
  15.             System.out.println("Late");
  16.             text="after";
  17.         }else if (diff<=30){
  18.             System.out.println("On time");
  19.         }else{
  20.             System.out.println("Early");
  21.         }
  22.         diff=Math.abs(diff);
  23.         if (diff>0&&diff<60){
  24.             System.out.printf("%d minutes %s the start",diff,text);
  25.         }else if (diff>=60){
  26.             System.out.printf("%d:%02d hours %s the start",diff/60,diff%60,text);
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement