Here you can find the source of mod(int x, int y)
private static int mod(int x, int y)
//package com.java2s; /*/*from ww w.j a v a 2 s . c o m*/ * Copyright (C) 2012 George Parisis * All rights reserved. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 as published by the Free Software Foundation. * * Alternatively, this software may be distributed under the terms of * the BSD license. * * See LICENSE and COPYING for more details. */ public class Main { /** * Perform (x mod y). This is necessary because the java % operator * is actually remainder instead of mod. Useless. * * @return x mod y */ private static int mod(int x, int y) { if ((x < 0) ^ (y < 0)) { return y + (x % y); } else { return x % y; } } }