StrictMath.floorMod(int, int): This method is available in java.lang.StrictMath class of Java.
Syntax:
int java.lang.StrictMath.floorMod(int x, int y)
This method takes two arguments of type int as its parameters. This method returns the floor modulus of the int arguments. The floor modulus is x - (floorDiv(x, y) * y), has the same sign as the divisor y, and is in the range of -abs(y) < r < +abs(y).
Parameters: Two parameters are required for this method.
x: the dividend.
y: the divisor.
Returns: the floor modulus x - (floorDiv(x, y) * y).
Throws:
ArithmeticException - if the divisor y is zero.
Approach 1: When no exceptions.
Java
public class StrictMathfloorModint {public static void main(String[] args) {int x = 1991, y = 18;System.out.println(StrictMath.floorMod(x, y));}}
Output:
11
Approach 2: ArithmeticException
Java
public class StrictMathfloorModint {public static void main(String[] args) {int x = 1991, y = 0;System.out.println(StrictMath.floorMod(x, y));}}
Output:
Exception in thread "main" java.lang.ArithmeticException: / by zero at java.base/java.lang.Math.floorMod(Math.java:1287) at java.base/java.lang.StrictMath.floorMod(StrictMath.java:1064)
No comments:
Post a Comment