-1
private long binomial(int n, int k) {
    if (k == 0 || k == n) {
        return 1;
    } else if (k > n) {
        return 0;
    } else if (0 < k && k < n) {
        return binomial(n - 1, k - 1) + binomial(n - 1, k);
    }
    return 0;
}

Hi, does anyone know how I can implement negative numbers into the method I've got so far? The arguments which aren't satisfied are; k<0 , n=0 , n<0. I'm not sure how to implement these so I've placed 'return 0' as a placeholder.

Andrew Coates
  • 119
  • 2
  • 12

1 Answers1

2

Wolfram has an article discussing what happens when the numbers are negative:

http://mathworld.wolfram.com/BinomialCoefficient.html

Cases

Southpaw
  • 43
  • 5
  • This is not an answer. Please avoid posting links as answers. – Mathews Mathai Mar 05 '16 at 19:53
  • Sorry, I understand why it is not a good enough answer, but what is stopping me from just copying and pasting from the website? I thought I was doing a service by at least providing the source? – Southpaw Mar 05 '16 at 20:00
  • Yes. Ideally, your answer is supposed to be a comment. Since you don't have enough reputation to comment, you should avoid posting answers like this to maintain your reputation so that you get the privilege to comment. Don't worry. Downvotes indicate that your answer is not qualified enough to appear here. No offence. – Mathews Mathai Mar 05 '16 at 20:04
  • Okay, Thanks! It appears the OP found it useful to a degree, though. – Southpaw Mar 05 '16 at 20:07