Guest User

Untitled

a guest
Feb 18th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. package de.hswt.bp4524.klee;
  2.  
  3. public class MainClass {
  4.  
  5. /**
  6. * @param args
  7. */
  8. public static void main(String[] args) {
  9. System.out.println(comb(49,50));
  10.  
  11. }
  12.  
  13. public static long comb(int n, int k){
  14. long ergebnis;
  15. if (k > n) throw new IllegalArgumentException( "k muss kleiner n sein!" );
  16. if (k == 0) return 1;
  17. if (2*k > n){ ergebnis = comb(n,n-k);
  18. return ergebnis;
  19. }
  20. else {
  21. ergebnis = n-k+1;
  22. for (int i = 2; i <= k; i++){
  23. ergebnis = ergebnis*(n-k+i);
  24. ergebnis = ergebnis/i;
  25. }
  26. return ergebnis;
  27. }
  28. // return ergebnis;
  29. }
  30. }
Add Comment
Please, Sign In to add comment