author | Jaroslav Tulach <jtulach@netbeans.org> |
Sat, 14 Jun 2008 09:51:05 +0200 | |
changeset 21 | 0aee50e597da |
parent 20 | afae7be94b25 |
child 184 | 6b2cd8df14c0 |
permissions | -rw-r--r-- |
1 package api;
3 /** Class to simplify arithmetical operations.
4 *
5 * @author Jaroslav Tulach <jtulach@netbeans.org>
6 * @version 1.0
7 */
8 // BEGIN: design.composition.arith1.0
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 public int sumRange(int from, int to) {
23 int len = to - from;
24 int[] array = new int[len + 1];
25 for (int i = 0; i <= len; i++) {
26 array[i] = from + i;
27 }
28 return sumAll(array);
29 }
30 }
31 // END: design.composition.arith1.0