VOOZH about

URL: https://www.geeksforgeeks.org/java/java-guava-binomialint-n-int-k-of-longmath-class-with-examples/

⇱ Java Guava | binomial(int n, int k) of LongMath Class with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Java Guava | binomial(int n, int k) of LongMath Class with Examples

Last Updated : 11 Jul, 2025
The binomial(int n, int k) method of Guava's LongMath Class accepts two parameters n and k and calculate the value of the binomial coefficient . If the calculated value overflows the maximum value of a long, then the method returns Long.MAX_VALUE i.e, the maximum value of a long. Syntax :
public static long binomial(int n, int k)
Parameters: This method accepts two parameters n and k and calculate the value of the binomial coefficient . Return Value : The method returns the binomial coefficient of n and k. Exceptions : The method binomial(int n, int k) throws IllegalArgumentException if n is negative, or k is negative or k is greater than n. Below examples illustrate the binomial() method of LongMath class: Example 1 :
Output:
Binomial Coefficient of 4 and 3 is : 4
Binomial Coefficient of 20 and 4 is : 4845
Example 2 :
Output:
java.lang.IllegalArgumentException: k (7) > n (5)
Reference : https://guava.dev/releases/20.0/api/docs/com/google/common/math/LongMath.html#binomial-int-int-
Comment