## 第一大题

### 第一问

```public static int numberOfLeapYears(int year1, int year2)
{
int count = 0;
for (int y = year1; y <= year2; y++)
{
if (isLeapYear(y))
{
count++;
}
}
return count;
}```

### 第二问

```public static int dayOfWeek(int month, int day, int year)
{
int startDay = firstDayOfYear(year);
int nthDay = dayOfYear(month, day, year);
int returnDay = (startDay + nthDay - 1) % 7;
return returnDay;
}```

## 第二大题

```public class StepTracker
{
private int minSteps;
private int totalSteps;
private int numDays;
private int numActiveDays;

public StepTracker(int threshold)
{
minSteps = threshold;
totalSteps = 0;
numDays = 0;
numActiveDays = 0;
}

{
totalSteps += steps;
numDays++;
if (steps >= minSteps)
{
numActiveDays++;
}
}

public int activeDays()
{
return numActiveDays;
}

public double averageSteps()
{
if (numDays == 0)
{
return 0.0;
}
else
{
return (double) totalSteps / numDays;
}
}
}```

## 第三大题

### 第一问

```public ArrayList<String> getDelimitersList(String[] tokens)
{
ArrayList<String> d = new ArrayList<String>();
for (String str : tokens)
{
if (str.equals(openDel) || str.equals(closeDel))
{
}
}
return d;
}
```

### 第二问

```public boolean isBalanced(ArrayList<String> delimiters)
{
int openCount = 0;
int closeCount = 0;

for (String str : delimiters)
{
if (str.equals(openDel))
{
openCount++;
}
else
{
closeCount++;
}
if (closeCount > openCount)
{
return false;
}
}
if (openCount == closeCount)
{
return true;
}
else
{
return false;
}
}```

## 第四大题

### 第一问

```public LightBoard(int numRows, int numCols)
{
lights = new boolean[numRows][numCols];

for (int r = 0; r < numRows; r++)
{
for (int c = 0; c < numCols; c++)
{
double rnd = Math.random();
lights[r][c] = rnd < 0.4;
}
}
}```

### 第二问

```public boolean evaluateLight(int row, int col)
{
int numOn = 0;

for (int r = 0; r < lights.length; r++)
{
if (lights[r][col])
{
numOn++;
}
}

if (lights[row][col] && numOn % 2 == 0)
{
return false;
}
if (!lights[row][col] && numOn % 3 == 0)
{
return true;
}
return lights[row][col];
}```