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 hourExam = Integer.parseInt(scanner.nextLine());
- int minuteExam = Integer.parseInt(scanner.nextLine());
- int hoursStudent = Integer.parseInt(scanner.nextLine());
- int minuteStudent = Integer.parseInt(scanner.nextLine());
- int examMinutes = hourExam * 60 + minuteExam;
- int studentMinutes = hoursStudent * 60 + minuteStudent;
- int time = Math.abs(studentMinutes - examMinutes);
- if (studentMinutes > examMinutes) {
- System.out.println("Late");
- if (time < 60) {
- System.out.printf("%d minutes after the start", time);
- } else {
- System.out.printf("%d:%02d hours after the start", time / 60, time % 60);
- }
- } else {
- if (time <= 30) {
- System.out.println("On time");
- } else {
- System.out.println("Early");
- }
- if (time != 0) {
- if (time < 60) {
- System.out.printf("%d minutes before the start", time);
- } else {
- System.out.printf("%d:%02d hours before the start", time / 60, time % 60);
- }
- }
- }
- }
- }
- ИЛИ:
- import java.util.Scanner;
- public class OnTimeForTheExam {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int hourExam = Integer.parseInt(scanner.nextLine());
- int minuteExam = Integer.parseInt(scanner.nextLine());
- int hoursStudent = Integer.parseInt(scanner.nextLine());
- int minuteStudent = Integer.parseInt(scanner.nextLine());
- int examMinutes = hourExam * 60 + minuteExam;
- int studentMinutes = hoursStudent * 60 + minuteStudent;
- int time = Math.abs(studentMinutes - examMinutes);
- System.out.println(studentMinutes > examMinutes ? "Late" : time <= 30 ? "On time" : "Early");
- Object o = time != 0
- ? (time < 60
- ? System.out.printf("%d minutes %s the start", time, studentMinutes > examMinutes ? "after" : "before")
- : System.out.printf("%d:%02d hours %s the start", time / 60, time % 60, studentMinutes > examMinutes ? "after" : "before"))
- : "";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement