VOOZH about

URL: https://www.geeksforgeeks.org/java/java-guava-modlong-x-long-m-of-longmath-class-with-examples/

⇱ Java Guava | mod(long x, long m) of LongMath Class with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Java Guava | mod(long x, long m) of LongMath Class with Examples

Last Updated : 11 Jul, 2025
The mod(long x, long m) method of Guava's LongMath Class accepts two parameters x and m, and used to calculate the value of x modulus under m. Syntax:
public static long mod(long x, long m)
Parameters: This method accepts two parameters x and m which are of long type to 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(long x, long m) throws ArithmeticException if m <= 0. Below examples illustrate the mod(long x, long m) method: Example 1 :
Output:
-77 mod 4 is : 3
22 mod 6 is : 4
Example 2:
Output:
java.lang.ArithmeticException: Modulus must be positive
Reference: https://guava.dev/releases/20.0/api/docs/com/google/common/math/LongMath.html#mod-long-int-
Comment