Java Integer Mod mod(int a, int b)

Here you can find the source of mod(int a, int b)

Description

Computes the mathematical modulus of two numbers.

License

Open Source License

Parameter

Parameter Description
a the dividend
b the divisor

Return

a mod b; that is, (((a % b) + b) % b)

Declaration

public static int mod(int a, int b) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*  ww w  .  j av  a 2s  . c  om*/
     * 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;
    }
}

Related

  1. mod(final int dividend, final int divisor)
  2. mod(final int dividend, final int divisor)
  3. mod(final int n, final int N)
  4. Mod(int a, int b)
  5. mod(int a, int b)
  6. mod(int a, int b)
  7. mod(int a, int n)