Advertisement
Guest User

Untitled

a guest
Nov 18th, 2016
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.53 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class u09 {
  4.     public static void main(String[] args) {
  5.         Scanner console = new Scanner(System.in);
  6.  
  7.         int examHours = Integer.parseInt(console.nextLine());
  8.         int examMinutes = Integer.parseInt(console.nextLine());
  9.         int studentHours = Integer.parseInt(console.nextLine());
  10.         int studentMinutes = Integer.parseInt(console.nextLine());
  11.  
  12.         int examTime = examHours * 60 + examMinutes;
  13.         int studentTime = studentHours * 60 + studentMinutes;
  14.         int minutesDifference = studentTime - examTime;
  15.  
  16.         if (minutesDifference < -30) {
  17.             System.out.println("Early");
  18.         } else if (minutesDifference <= 0) {
  19.             System.out.println("On time");
  20.         } else {
  21.             System.out.println("Late");
  22.         } if (minutesDifference != 0) {
  23.             int hours = Math.abs(minutesDifference / 60);
  24.             int minutes = Math.abs(minutesDifference % 60);
  25.             if (hours > 0) {
  26.                 if (minutes < 10) {
  27.                     System.out.println(hours + ":0" + minutes + " hours");
  28.                 } else {
  29.                     System.out.println(hours + ":" + minutes + " hours");
  30.                 }
  31.             } else {
  32.                 System.out.print(minutes + " minutes");
  33.                 if (minutesDifference < 0) {
  34.                     System.out.print(" before the start");
  35.                 } else {
  36.                     System.out.print(" after the start");
  37.                 }
  38.             }
  39.         }
  40.  
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement