import java.time.LocalDate;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int month = scanner.nextInt();
int week = scanner.nextInt();
int dayofweek = scanner.nextInt();
int start_year = scanner.nextInt();
int end_year = scanner.nextInt();
for(int i = start_year; i <= end_year; i++){
LocalDate ld = LocalDate.of(i, month,1);
int _dayofweek = ld.getDayOfWeek().getValue();
LocalDate newld = LocalDate.now();
if(_dayofweek <= dayofweek)
{
newld = ld.plusDays((week - 1) * 7 + ( dayofweek-_dayofweek));
}
else
{
newld = ld.plusDays(week * 7 + ( dayofweek-_dayofweek));
}
if(ld.getMonth() == newld.getMonth()){
System.out.println(newld.toString().replace("-","/"));
}
else{
System.out.println("none");
}
}
}
}
另一种解法
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int month = scanner.nextInt();
int week = scanner.nextInt();
int dayofweek = scanner.nextInt();
int start_year = scanner.nextInt();
int end_year = scanner.nextInt();
for(int i = start_year; i <= end_year; i++){
LocalDate ld = LocalDate.of(i,1,1);
ld = ld.plusMonths(month-1);
LocalDate newld = ld.with(TemporalAdjusters.dayOfWeekInMonth(week, DayOfWeek.of(dayofweek)));
if(ld.getMonth() == newld.getMonth()){
System.out.println(newld.toString().replace("-","/"));
}
else{
System.out.println("none");
}
}
}
}