Javatpoint Logo
Javatpoint Logo

Java Math.floorDiv() method

The java.lang.Math.floorDiv() is used to find the largest integer value that is less than or equal to the algebraic quotient. This method first divide the first argument by the second argument and then performs a floor() operation over the result and returns the integer that is less or equal to the quotient.

Syntax

Parameter

Return

  • If the first argument is int or long value and second argument is -1, this method will return the first argument as output.
  • If the second argument is zero, this method will throw ArithmeticException.

Example 1

Test it Now

Output:

8

Example 2

Test it Now

Output:

-9

Example 3

Test it Now

Output:

Runtime Error:
Exception in thread "main" java.lang.ArithmeticException: / by zero
	at java.lang.Math.floorDiv(Math.java:1052)
	at floorDivExample1.main(floorDivExample1.java:8)

Example 4

Test it Now

Output:

-2148

Next TopicJava Math





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA