title: Java Modular Arithmetic
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/5385024/mod-in-java-produces-negative-numbers">Mod in Java produces negative numbers</a>  </p>
  </blockquote>
  
  
  
  <p>When I try to print -16 mod 57, I should get 41. However, I keep getting -16 as my answer. What gives?    </p>
  
  <p>Here is my code:</p>
  
  <pre><code>public class TestMod {
  
  public static void main(String[] args) {
      int number = -16;
      int mod = 57;
      int answer = number%mod;
      System.out.println(answer);
  
  }
  
  }
  </code></pre>