fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.time.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main(String[] args) {
  12. var test = new Scanner(System.in);
  13. while (test.hasNext()) {
  14. var from = LocalDate.parse(test.next());
  15. test.skip(" to ");
  16. var to = LocalDate.parse(test.next());
  17. test.nextLine();
  18. System.out.printf("%s to %s = %s%n", from, to, compareMonth(from, to));
  19. }
  20. }
  21.  
  22. // negative if less, positive if greater than one month
  23. static int compareMonth(LocalDate from, LocalDate to) {
  24. var end = from.plusMonths(1).minusDays(1);
  25. return to.compareTo(end);
  26. }
  27. }
Success #stdin #stdout 0.14s 50168KB
stdin
2022-06-01 to 2022-06-30
2022-06-02 to 2022-06-30
2022-06-01 to 2022-07-01
2022-06-15 to 2022-07-15
2022-06-15 to 2022-07-14
stdout
2022-06-01 to 2022-06-30  =  0
2022-06-02 to 2022-06-30  =  -1
2022-06-01 to 2022-07-01  =  1
2022-06-15 to 2022-07-15  =  1
2022-06-15 to 2022-07-14  =  0