fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. import java.time.* ;
  8. import java.time.temporal.* ;
  9.  
  10. /* Name of the class has to be "Main" only if the class is public. */
  11. class Ideone
  12. {
  13. public static void main (String[] args) throws java.lang.Exception
  14. {
  15. List<LocalDate> mondays = new ArrayList<>() ;
  16. List<LocalDate> wednesdays = new ArrayList<>() ;
  17. List<LocalDate> thursdays = new ArrayList<>() ;
  18.  
  19. LocalDate today = LocalDate.now( ZoneId.of( "America/Montreal" ) ) ;
  20. LocalDate twoMonthsLater = today.plusMonths( 2 );
  21.  
  22. LocalDate localDate = today ;
  23. while ( localDate.isBefore( twoMonthsLater ) ) {
  24. DayOfWeek dow = localDate.getDayOfWeek() ;
  25. switch ( dow ) {
  26. case MONDAY:
  27. mondays.add( localDate ) ;
  28. break;
  29.  
  30. case WEDNESDAY:
  31. wednesdays.add( localDate ) ;
  32. break;
  33.  
  34. case THURSDAY:
  35. thursdays.add( localDate ) ;
  36. break;
  37.  
  38. default:
  39. // Ignore any other day-of-week.
  40. break;
  41. }
  42. // Set-up the next loop.
  43. localDate = localDate.plusDays( 1 ) ;
  44. }
  45.  
  46. System.out.println( "From " + today + " to " + twoMonthsLater + ":" );
  47. System.out.println( "mondays: " + mondays ) ;
  48. System.out.println( "wednesdays: " + wednesdays ) ;
  49. System.out.println( "thursdays: " + thursdays ) ;
  50. }
  51.  
  52.  
  53. }
Success #stdin #stdout 0.16s 4386816KB
stdin
Standard input is empty
stdout
From 2017-10-17 to 2017-12-17:
mondays: [2017-10-23, 2017-10-30, 2017-11-06, 2017-11-13, 2017-11-20, 2017-11-27, 2017-12-04, 2017-12-11]
wednesdays: [2017-10-18, 2017-10-25, 2017-11-01, 2017-11-08, 2017-11-15, 2017-11-22, 2017-11-29, 2017-12-06, 2017-12-13]
thursdays: [2017-10-19, 2017-10-26, 2017-11-02, 2017-11-09, 2017-11-16, 2017-11-23, 2017-11-30, 2017-12-07, 2017-12-14]