32 lines
661 B
Java
32 lines
661 B
Java
package de.wwwu.awolf.presenter.util;
|
|
|
|
/**
|
|
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
|
|
*
|
|
* @Author: Armin Wolf
|
|
* @Email: a_wolf28@uni-muenster.de
|
|
* @Date: 26.06.2017.
|
|
*/
|
|
public class BinomialCoeffizient {
|
|
/**
|
|
* Berechnet den Binomialkoeffizient zu der eingabe. Bin(n,k)
|
|
*
|
|
* @param n n
|
|
* @param k k
|
|
* @return Ergebnis
|
|
*/
|
|
public static Double run(int n, int k) {
|
|
int res = 1;
|
|
|
|
if (k > n - k)
|
|
k = n - k;
|
|
|
|
for (int i = 0; i < k; ++i) {
|
|
res *= (n - i);
|
|
res /= (i + 1);
|
|
}
|
|
|
|
return Double.valueOf(res);
|
|
}
|
|
}
|