title: Addition in field with finite int elements?
body: <p>I need to write a function (in Java) which has the following input:</p>
  
  <ol>
  <li><code>int amountFieldElements</code></li>
  <li><code>int summandOne</code></li>
  <li><code>int summandTwo</code></li>
  </ol>
  
  <p><code>amountFieldElement</code> describes the amount of int numbers in a range starting from 1 (e.g. 1, 2, 3, 4 or just 1). <code>summandOne</code> is a int from this range, <code>summandTwo</code> can be any non-negative int.</p>
  
  <p>The function has to add <code>summandTwo</code> to <code>summandOne</code>. If the result is bigger then <code>amountFieldElement</code>, it has to start over from 1.</p>
  
  <p>I tried to simply use modulo: (summandOne + summandTwo) % amountFieldElements</p>
  
  <p>But this is often wrong, e.g. <code>(3 + 1) % 4 = 0</code> but I'd need it to be <code>4</code>.</p>
  
  <p>Example: If amountFieldElements = <code>4</code>:</p>
  
  <p><code>2 + 2 = 4</code> would stay as <code>4</code></p>
  
  <p><code>3 + 2 = 5</code> would become <code>1</code></p>
  
  <p><code>4 + 2 = 6</code> would become <code>2</code> etc</p>
  
  <p>or for <code>amountFieldElements = 1</code></p>
  
  <p><code>1 + 0 = 1</code> would stay as <code>1</code></p>
  
  <p><code>1 + 1 = 2</code> would also be <code>1</code></p>
  
  <p>-> any result would be 1 here</p>