Advertisement
cd62131

SubstructTime.java

May 17th, 2018
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.78 KB | None | 0 0
  1. import java.time.LocalDateTime;
  2. import java.util.Scanner;
  3.  
  4. public class SubstructTime {
  5.  
  6.   public static void main(String[] args) {
  7.     LocalDateTime d = LocalDateTime.now();
  8.     System.out.format("now: %tT", d);
  9.     System.out.println();
  10.  
  11.     String[] term = { "hour", "minute", "second" };
  12.     int[] sub = new int[term.length];
  13.     Scanner in = new Scanner(System.in);
  14.     for (int i = 0; i < term.length; ++i) {
  15.       System.out.format("%s? ", term[i]);
  16.       try {
  17.         sub[i] = Integer.parseInt(in.next());
  18.       } catch (Exception e) {
  19.         e.printStackTrace(System.err);
  20.       }
  21.     }
  22.     in.close();
  23.  
  24.     System.out.format(
  25.         "sub: %tT",
  26.         d.minusHours(sub[0]).minusMinutes(sub[1]).minusSeconds(sub[2])
  27.     );
  28.     System.out.println();
  29.   }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement