Advertisement
Spocoman

08. On Time for the Exam

Aug 26th, 2024
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.45 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class OnTimeForTheExam {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int hourExam = Integer.parseInt(scanner.nextLine());
  7.         int minuteExam = Integer.parseInt(scanner.nextLine());
  8.         int hoursStudent = Integer.parseInt(scanner.nextLine());
  9.         int minuteStudent = Integer.parseInt(scanner.nextLine());
  10.  
  11.         int examMinutes = hourExam * 60 + minuteExam;
  12.         int studentMinutes = hoursStudent * 60 + minuteStudent;
  13.         int time = Math.abs(studentMinutes - examMinutes);
  14.  
  15.         if (studentMinutes > examMinutes) {
  16.             System.out.println("Late");
  17.             if (time < 60) {
  18.                 System.out.printf("%d minutes after the start", time);
  19.             } else {
  20.                 System.out.printf("%d:%02d hours after the start", time / 60, time % 60);
  21.             }
  22.         } else {
  23.             if (time <= 30) {
  24.                 System.out.println("On time");
  25.             } else {
  26.                 System.out.println("Early");
  27.             }
  28.             if (time != 0) {
  29.                 if (time < 60) {
  30.                     System.out.printf("%d minutes before the start", time);
  31.                 } else {
  32.                     System.out.printf("%d:%02d hours before the start", time / 60, time % 60);
  33.                 }
  34.             }
  35.         }
  36.     }
  37. }
  38.  
  39. ИЛИ:
  40.  
  41. import java.util.Scanner;
  42.  
  43. public class OnTimeForTheExam {
  44.     public static void main(String[] args) {
  45.         Scanner scanner = new Scanner(System.in);
  46.         int hourExam = Integer.parseInt(scanner.nextLine());
  47.         int minuteExam = Integer.parseInt(scanner.nextLine());
  48.         int hoursStudent = Integer.parseInt(scanner.nextLine());
  49.         int minuteStudent = Integer.parseInt(scanner.nextLine());
  50.  
  51.         int examMinutes = hourExam * 60 + minuteExam;
  52.         int studentMinutes = hoursStudent * 60 + minuteStudent;
  53.         int time = Math.abs(studentMinutes - examMinutes);
  54.  
  55.         System.out.println(studentMinutes > examMinutes ? "Late" : time <= 30 ? "On time" : "Early");
  56.         Object o = time != 0
  57.                 ? (time < 60
  58.                         ? System.out.printf("%d minutes %s the start", time, studentMinutes > examMinutes ? "after" : "before")
  59.                         : System.out.printf("%d:%02d hours %s the start", time / 60, time % 60, studentMinutes > examMinutes ? "after" : "before"))
  60.                 : "";
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement