Here you can find the source of mod(int a, int n)
public static int mod(int a, int n)
//package com.java2s; // License: GPL. For details, see LICENSE file. public class Main { /**//from w ww .ja v a 2 s .co m * return the modulus in the range [0, n) */ public static int mod(int a, int n) { if (n <= 0) throw new IllegalArgumentException(); int res = a % n; if (res < 0) { res += n; } return res; } }