mardi 8 octobre 2019

Writing a function for combination- Java

Write a static method to compute the number of ways to select k elements of from a set of size n --- i.e., n choose k.

For k ≤ n and both non-negative, n choose k is n!/k!(n-K)!

If k exceeds n, the result is 0. If either input is negative, that is an invalid input: throw a java.lang.IllegalArgumentException in such cases, specifying which argument was bad. Throw different exceptions depending on whether n, k, or both, are negative.

Please help if possible. I am really new to programming.

Aucun commentaire:

Enregistrer un commentaire