author | Jaroslav Tulach <jaroslav.tulach@apidesign.org> |
Thu, 30 Oct 2014 21:30:10 +0100 | |
changeset 409 | 40cabcdcd2be |
permissions | -rw-r--r-- |
jtulach@321 | 1 |
package org.apidesign.math.test; |
jtulach@321 | 2 |
|
jtulach@321 | 3 |
import org.apidesign.math.Arithmetica; |
jtulach@321 | 4 |
|
jtulach@321 | 5 |
/** Class showing inventive, non-expected use of |
jtulach@321 | 6 |
* Arithmetica methods to do multiplication instead of |
jtulach@321 | 7 |
* addition. |
jtulach@321 | 8 |
*/ |
jtulach@321 | 9 |
// BEGIN: design.composition.arith.factorial |
jtulach@321 | 10 |
public final class Factorial extends Arithmetica { |
jtulach@321 | 11 |
public static int factorial(int n) { |
jtulach@321 | 12 |
return new Factorial().sumRange(1, n); |
jtulach@321 | 13 |
} |
jtulach@321 | 14 |
@Override |
jtulach@321 | 15 |
public int sumTwo(int one, int second) { |
jtulach@321 | 16 |
return one * second; |
jtulach@321 | 17 |
} |
jtulach@321 | 18 |
} |
jtulach@321 | 19 |
// END: design.composition.arith.factorial |
jtulach@321 | 20 |