Java Guava | mod() method of IntMath Class Last Updated : 23 Jan, 2019 Comments Improve Suggest changes Like Article Like Report 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. Syntax : 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 : Java // Java code to show implementation of // mod(int x, int m) method of Guava's // IntMath class import java.math.RoundingMode; import com.google.common.math.IntMath; class GFG { // Driver code public static void main(String args[]) { int x1 = -84; int m1 = 5; int ans1 = IntMath.mod(x1, m1); // Using mod(int x, int m) // method of Guava's IntMath class System.out.println(x1 + " mod " + m1 + " is : " + ans1); int x2 = 14; int m2 = 6; int ans2 = IntMath.mod(x2, m2); // Using mod(int x, int m) // method of Guava's IntMath class System.out.println(x2 + " mod " + m2 + " is : " + ans2); } } Output : -84 mod 5 is : 1 14 mod 6 is : 2 Example 2 : Java // Java code to show implementation of // mod(int x, int m) method of Guava's // IntMath class import java.math.RoundingMode; import com.google.common.math.IntMath; class GFG { static int findMod(int x, int m) { try { // Using mod(int x, int m) // method of Guava's IntMath class // This should throw "ArithmeticException" // as m <= 0 int ans = IntMath.mod(x, m); // Return the answer return ans; } catch (Exception e) { System.out.println(e); return -1; } } // Driver code public static void main(String args[]) { int x = 14; int m = -3; try { // Function calling findMod(x, m); } catch (Exception e) { System.out.println(e); } } } Output : java.lang.ArithmeticException: Modulus -3 must be > 0 Reference : https://google.github.io/guava/releases/20.0/api/docs/com/google/common/math/IntMath.html#mod-int-int- Comment More infoAdvertise with us Next Article Java Guava | mod() method of IntMath Class bansal_rtk_ Follow Improve Article Tags : Misc Java Java-Functions java-guava Practice Tags : JavaMisc Similar Reads Java Guava | isPrime() method of IntMath Class The isPrime(int n) method of Guava's IntMath class is used to check whether the parameter passed to it is a prime number or not. If the parameter passed to it is prime, then it returns True otherwise it returns False. A number is said to be Prime if it is divisible only by 1 and the number itself. S 2 min read IntMath Class | Guava | Java Introduction : IntMath is used to perform mathematical operations on Integer values. Basic standalone math functions are divided into the classes IntMath, LongMath, DoubleMath, and BigIntegerMath based on the primary numeric type involved. These classes have parallel structure, but each supports onl 3 min read Java Guava | gcd(int a, int b) method of IntMath Class The method gcd(int a, int b) of Guava's IntMath class returns the greatest common divisor of a, b. Syntax : public static int gcd(int a, int b) Where a and b are integers. Return Value : Greatest common divisor of integers a and b. Exceptions : The method gcd(int a, int b) throws IllegalArgumentExce 2 min read Java Guava | isPowerOfTwo() method IntMath Class The isPowerOfTwo() method of Guava's IntMath class is used to check if a number is power of two or not. It accepts the number to be checked as a parameter and return boolean value true or false based on whether the number is a power of 2 or not. Syntax : public static boolean isPowerOfTwo(int x) Par 2 min read Java Guava | ceilingPowerOfTwo() method of IntMath Class The ceilingPowerOfTwo(int x) method of Guava's IntMath class accepts a parameter and calculates the smallest power of two greater than the values passed in the parameter. This method is equivalent to checkedPow(2, log2(x, CEILING)). Syntax : public static int ceilingPowerOfTwo(int x) Parameter: This 2 min read Ints Class | Guava | Java Ints is a utility class for primitive type int. It provides Static utility methods pertaining to int primitives, that are not already found in either Integer or Arrays. Declaration : @GwtCompatible(emulated=true) public final class Ints extends Object Below table shows the Field summary for Guava In 3 min read Method Class | getModifiers() method in Java The java.lang.reflect.Method.getModifiers() method of Method class returns the modifiers for the method represented by this Method object. It returns int value. Then with the use Modifier class, the name of modifiers corresponding to that value is fetched. Syntax: public int getModifiers() Return Va 3 min read LongMath Class | Guava | Java LongMath is used to perform mathematical operations on Long values. Basic standalone math functions are divided into the classes IntMath, LongMath, DoubleMath, and BigIntegerMath based on the primary numeric type involved. These classes have parallel structure, but each supports only the relevant su 3 min read Java Guava | IntMath.divide(int, int, RoundingMode) method with Examples The divide(int p, int q, RoundingMode mode) method of Guava's IntMath Class accepts three parameters and calculates the result of dividing first parameter by second parameter, rounded according to the rounding mode specified by the third parameter. Syntax: public static int divide(int p, int q, Roun 3 min read Modifier isNative(mod) method in Java with Examples The isNative(mod) method of java.lang.reflect.Modifier is used to check if the integer argument includes the native modifier or not. If this integer parameter represents native type Modifier then method returns true else false. Syntax: public static boolean isNative(int mod) Parameters: This method 2 min read Like