3 /** Class to simplify arithmetical operations, improved version to compute
4 * the sum for ranges, but only if the virtual machine is configured to
5 * run in incompatible mode.
7 * @author Jaroslav Tulach <jtulach@netbeans.org>
10 // BEGIN: design.composition.arith2.0.property
11 public class Arithmetica {
12 public int sumTwo(int one, int second) {
16 public int sumAll(int... numbers) {
18 for (int i = 1; i < numbers.length; i++) {
19 sum = sumTwo(sum, numbers[i]);
24 public int sumRange(int from, int to) {
25 if (Boolean.getBoolean("arithmetica.v2")) {
26 return sumRange2(from, to);
28 return sumRange1(from, to);
32 private int sumRange1(int from, int to) {
34 int[] array = new int[len + 1];
35 for (int i = 0; i <= len; i++) {
41 private int sumRange2(int from, int to) {
42 return (from + to) * (to - from + 1) / 2;
44 // END: design.composition.arith2.0.property