title: Java Easter calculator for 2016 using the Gauss algorithm
body: <p>I'm making Easter Sunday calculator using the <a href="https://en.wikipedia.org/wiki/Computus#Gauss_algorithm" rel="nofollow">Gauss algorithm</a> for the next 10 years.</p>
  
  <p>It seems to work fine except several years. For example it tells that in 2016 Easter will be on 2016-03-27, but it will be on the 2016-05-01. It works fine with other years.</p>
  
  <p>This is my code:</p>
  
  <pre><code>public class EasterCalculator {
  public static void main(String[] args) {
      EasterCalculator obj = new EasterCalculator();
      DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyy");
  
      for (int i = 2016; i &lt; 2026; i++) {
          System.out.println("Easter  in " + i + " will be on " + obj.getEasterDate(i).format(formatter));
          System.out.println("Trinity in " + i + " will be on " + obj.getEasterDate(i).plusWeeks(7).format(formatter));
          System.out.println();
      }
  }
  
  public LocalDate getEasterDate(int year) {
      int a = year % 19;
      int b = year % 4;
      int c = year % 7;
      int k = year / 100;
      int p = (13 + 8 * k) / 25;
      int q = k / 4;
      int M = (15 - p + k - q) % 30;
      int N = (4 + k - q) % 7;
      int d = (19 * a + M) % 30;
      int e = (2 * b + 4 * c + 6 * d + N) % 7;
  
      if (d == 29 &amp;&amp; e == 6) {
          return LocalDate.of(year, 3, 22).plusDays(d + e).minusDays(7);
      } else
          return LocalDate.of(year, 3, 22).plusDays(d + e);
  }
  }
  </code></pre>