Java Integer Mod mod(int num, int div)

Here you can find the source of mod(int num, int div)

Description

Returns the modulus of the input value (taking care of the sign of the value)

License

Open Source License

Parameter

Parameter Description
num Input number
div Divisor for modulus

Return

Modulus of num by div

Declaration

public static int mod(int num, int div) 

Method Source Code

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

public class Main {
    /**//  ww w.  j  ava2s.  c  o  m
     * Returns the modulus of the input value (taking care of the sign of the value)
     * 
     * @param num Input number
     * @param div Divisor for modulus
     * @return Modulus of num by div
     */
    public static int mod(int num, int div) {
        if (num < 0) {
            return div - (-num % div);
        } else {
            return num % div;
        }
    }
}

Related

  1. mod(int a, int n)
  2. mod(int a, int n)
  3. mod(int divisor, int dividend)
  4. mod(int hash, int size)
  5. mod(int i, int n)
  6. mod(int v, int m)
  7. mod(int x, int y)
  8. mod(int x, int y)
  9. mod(int x, int y)