Math floorDiv() method in Java
The java.lang.Math.floorDiv() is a built-in math function in java which returns the largest (closest to positive infinity) int value that is less than or equal to the algebraic quotient. As floorDiv() is static, so object creation is not required.
Syntax:
public static int floorDiv(data_type x, data_type y)
Parameter: The function accepts two parameters as described below.
Exception:
- ArithmeticException: It throws ArithmeticException if the divisor is zero.
Return Value: This method returns the largest (closest to positive infinity) integer value that is less than or equal to the algebraic quotient.
Below programs illustrate the java.lang.Math.floorDiv() method:
Program 1:
import java.lang.Math;
class Gfg1{
public static void main(String args[])
{
int a = 25 , b = 5 ;
System.out.println(Math.floorDiv(a, b));
int c = 125 , d = 50 ;
System.out.println(Math.floorDiv(c, d));
}
}
|
Program 2:
import java.lang.Math;
class Gfg2 {
public static void main(String args[])
{
int x = 200 ;
int y = 0 ;
System.out.println(Math.floorDiv(x, y));
}
}
|
Output:
Runtime Error :
Exception in thread "main" java.lang.ArithmeticException: / by zero
at java.lang.Math.floorDiv(Math.java:1052)
at Gfg2.main(File.java:13)
Last Updated :
20 Jun, 2018
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...