Java Guava | mod() method of IntMath Class
The mod(int x, int m) method of Guava’s IntMath class accepts two parameters x and m and used to calculate the value of x modulus under m.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
public static int mod(int x, int m)
Parameters: This method accepts two parameters x and m which are of integer types and calculate x modulo m.
Return Value : The method returns x mod m that will be a non-negative value less than m.
Exception : The method mod(int x, int m) throws ArithmeticException if m <= 0.
Below examples illustrate the mod(int x, int m) method:
Example 1 :
-84 mod 5 is : 1 14 mod 6 is : 2
Example 2 :
java.lang.ArithmeticException: Modulus -3 must be > 0