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.
- x: The first parameter refers to the dividend value.
- y: The second parameter refers to the divisor value.
The parameters can be data-type int or long.
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:
// Java program to demonstrate working // of java.lang.Math.floorDiv() method import java.lang.Math; class Gfg1{ // driver code public static void main(String args[]) { int a = 25, b = 5; System.out.println(Math.floorDiv(a, b)); // 125/50 value is 2.5, but as output is integer // less than or equal to 2.5, So output is 2 int c = 125, d = 50; System.out.println(Math.floorDiv(c, d)); } } |
5 2
Program 2:
// Java program to demonstrate working // of java.lang.Math.floorDiv() method import java.lang.Math; class Gfg2 { // driver code 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)
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
Recommended Posts:
- Java.math.BigInteger.modInverse() method in Java
- Java.math.BigInteger.probablePrime() method in Java
- Java.lang.Math Class in Java | Set 1
- Java.lang.Math Class in Java | Set 2
- java.lang.Math.atan2() in Java
- Java Math random() method with Examples
- Java Math asin() method with Example
- Java Math min() method with Examples
- Java Math max() method with Examples
- Java Math log() method with example
- Java Math abs() method with Examples
- Java Math acos() method with Examples
- Java Math hypot() method with Example
- Java Math exp() method with Example
- Java Math sin() method with Examples
- Java Math sinh() method with Examples
- Java Math cosh() method with Examples
- Java Math tanh() method with Examples
- Java Math cos() method with Examples
- Java Math tan() method with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

