author | Jaroslav Tulach <jtulach@netbeans.org> |
Sat, 14 Jun 2008 10:01:34 +0200 | |
changeset 186 | 09d10795f55c |
parent 184 | 6b2cd8df14c0 |
child 187 | e8db9f297016 |
permissions | -rw-r--r-- |
1 package api;
3 /** Class to simplify arithmetical operations, improved version to compute
4 * the sum for ranges.
5 *
6 * @author Jaroslav Tulach <jtulach@netbeans.org>
7 * @version 2.0
8 */
9 public class Arithmetica {
10 public int sumTwo(int one, int second) {
11 return one + second;
12 }
14 public int sumAll(int... numbers) {
15 int sum = numbers[0];
16 for (int i = 1; i < numbers.length; i++) {
17 sum = sumTwo(sum, numbers[i]);
18 }
19 return sum;
20 }
22 // BEGIN: design.composition.arith2.0
23 public int sumRange(int from, int to) {
24 return (from + to) * (to - from + 1) / 2;
25 }
26 // END: design.composition.arith2.0
27 }