Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
32
Task/Five-weekends/Java/five-weekends.java
Normal file
32
Task/Five-weekends/Java/five-weekends.java
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
|
||||
public class FiveFSS {
|
||||
private static boolean[] years = new boolean[201];
|
||||
private static int[] month31 = {Calendar.JANUARY, Calendar.MARCH, Calendar.MAY,
|
||||
Calendar.JULY, Calendar.AUGUST, Calendar.OCTOBER, Calendar.DECEMBER};
|
||||
|
||||
public static void main(String[] args) {
|
||||
StringBuilder months = new StringBuilder();
|
||||
int numMonths = 0;
|
||||
for (int year = 1900; year <= 2100; year++) {
|
||||
for (int month : month31) {
|
||||
Calendar date = new GregorianCalendar(year, month, 1);
|
||||
if (date.get(Calendar.DAY_OF_WEEK) == Calendar.FRIDAY) {
|
||||
years[year - 1900] = true;
|
||||
numMonths++;
|
||||
//months are 0-indexed in Calendar
|
||||
months.append((date.get(Calendar.MONTH) + 1) + "-" + year +"\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("There are "+numMonths+" months with five weekends from 1900 through 2100:");
|
||||
System.out.println(months);
|
||||
System.out.println("Years with no five-weekend months:");
|
||||
for (int year = 1900; year <= 2100; year++) {
|
||||
if(!years[year - 1900]){
|
||||
System.out.println(year);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue