Advertisement
dimipan80

C#Exams 1. Exam Schedule (on Java Code, using LocalTime)

Aug 23rd, 2014
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. import java.time.LocalTime;
  2. import java.time.format.DateTimeFormatter;
  3. import java.util.Scanner;
  4.  
  5. public class _1_ExamSchedule {
  6.  
  7.     public static void main(String[] args) {
  8.         // TODO Auto-generated method stub
  9.         Scanner scan = new Scanner(System.in);
  10.         int startHour = scan.nextInt();
  11.         int startMinute = scan.nextInt();
  12.         String partOfDay = scan.next();
  13.         int durationHours = scan.nextInt();
  14.         int durationMinutes = scan.nextInt();
  15.  
  16.         if (partOfDay.equals("PM")) {
  17.             startHour += 12;
  18.         }
  19.  
  20.         LocalTime start = LocalTime.of(startHour, startMinute);
  21.         LocalTime end = start.plusHours(durationHours).plusMinutes(
  22.                 durationMinutes);
  23.  
  24.         DateTimeFormatter timeFormat = DateTimeFormatter.ofPattern("hh:mm:a");
  25.         System.out.println(end.format(timeFormat));
  26.     }
  27.  
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement