Skip to content

Instantly share code, notes, and snippets.

@SiAust
Created August 26, 2020 10:08
Show Gist options
  • Save SiAust/2ae19121f5db9ee674911d2c094f0efd to your computer and use it in GitHub Desktop.
Save SiAust/2ae19121f5db9ee674911d2c094f0efd to your computer and use it in GitHub Desktop.
Output each Monday of a given month.
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] input = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
LocalDate date = LocalDate.of(input[0], input[1], 1);
for (int i = 0; i < date.lengthOfMonth(); i++) {
if (date.plusDays(i).getDayOfWeek() == DayOfWeek.MONDAY) {
System.out.println(date.plusDays(i));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment