title: Java: How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?
body: <p>I am new to programming and java and I am trying to solve the following problem:
  How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>int count, sum = 0;           
  for (int i = 1901; i &lt; 2001; i++) {
      LocalDate test = LocalDate.of(i, 1, 1);
      sum += test.lengthOfYear();
  }
  for (int i = 1; i &lt; sum; i++) {
      LocalDate date1 = LocalDate.of(1901, 1, 1);
      date1 = date1.plusDays(i);
      if (date1.getMonth() == JANUARY &amp;&amp; date1.getDayOfWeek() == SUNDAY) {
          count++;
      }
  }
  System.out.println(count);
  </code></pre>
  
  <p>If I print the results, it seems to be working fine.</p>
  
  <p>My result is 443, but the correct answer is 171. What am I doing wrong?</p>
  
  <p>Thank you!</p>