Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.time.LocalDateTime;
- import java.util.Scanner;
- public class SubstructTime {
- public static void main(String[] args) {
- LocalDateTime d = LocalDateTime.now();
- System.out.format("now: %tT", d);
- System.out.println();
- String[] term = { "hour", "minute", "second" };
- int[] sub = new int[term.length];
- Scanner in = new Scanner(System.in);
- for (int i = 0; i < term.length; ++i) {
- System.out.format("%s? ", term[i]);
- try {
- sub[i] = Integer.parseInt(in.next());
- } catch (Exception e) {
- e.printStackTrace(System.err);
- }
- }
- in.close();
- System.out.format(
- "sub: %tT",
- d.minusHours(sub[0]).minusMinutes(sub[1]).minusSeconds(sub[2])
- );
- System.out.println();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement