StrictMath.floorMod(long, long): This method is available in java.lang.StrictMath class of Java.
Syntax:
long java.lang.StrictMath.floorMod(long x, long y)
This method takes two arguments of type long as its parameters. This method returns the floor modulus of the long 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 StrictMathfloorModlong {public static void main(String[] args) {long x = 19199191, y = 1919;System.out.println(StrictMath.floorMod(x, y));}}
Output:
1515
Approach 2: ArithmeticException
Java
public class StrictMathfloorModlong {public static void main(String[] args) {long x = 19199191, 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:1345) at java.base/java.lang.StrictMath.floorMod(StrictMath.java:1119)
No comments:
Post a Comment