Skip to content

Commit

Permalink
Update Calculator.java
Browse files Browse the repository at this point in the history
  • Loading branch information
giusepped committed Aug 20, 2014
1 parent 7c586f1 commit 1a40b0a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Week9/MethodArgumentValidation/Validation/Calculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
public class Calculator {

public int multiplication(int fromInteger) {

if(fromInteger < 0){
throw new IllegalArgumentException("negative numbers are not accepted");
}
int multiplication = 1;
for (int i = 1; i <= fromInteger; i++) {
multiplication *= i;
Expand All @@ -13,7 +15,9 @@ public int multiplication(int fromInteger) {
}

public int binomialCoefficient(int setSize, int subsetSize) {

if(setSize < 0 || subsetSize < 0 || subsetSize > setSize){
throw new IllegalArgumentException("invalid entries");
}
int numerator = multiplication(setSize);
int denominator = multiplication(subsetSize) * multiplication(setSize - subsetSize);

Expand Down

0 comments on commit 1a40b0a

Please sign in to comment.