Java examples for java.lang:Math Number
Computes the mathematical modulus of two numbers.
//package com.java2s; public class Main { /**//from www . j a v a2s.co m * Computes the mathematical modulus of two numbers. * * <p> * The Java <code>%</code> operator returns a result that adopts the sign of the dividend; however, a true mathematical modulus adopts the sign of the divisor. This method implements a mathematical modulus. * </p> * * @param a the dividend * @param b the divisor * @return a mod b; that is, <code>(((a % b) + b) % b)</code> */ public static int mod(int a, int b) { return ((a % b) + b) % b; } }