samples/composition/src-api1.0/api/Arithmetica.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:51:05 +0200
changeset 20 afae7be94b25
parent 17 af005434d27f
child 21 0aee50e597da
permissions -rw-r--r--
Fixing the optimized 2.0 implementation and adding yet another test for factorial of 4
     1 package api;
     2 
     3 /** Class to simplify arithmetical operations.
     4  *
     5  * @author Jaroslav Tulach <jtulach@netbeans.org>
     6  * @version 1.0
     7  */
     8 public class Arithmetica {
     9     public int sumTwo(int one, int second) {
    10         return one + second;
    11     }
    12     
    13     public int sumAll(int... numbers) {
    14         int sum = numbers[0];
    15         for (int i = 1; i < numbers.length; i++) {
    16             sum = sumTwo(sum, numbers[i]);
    17         }
    18         return sum;
    19     }
    20     
    21     public int sumRange(int from, int to) {
    22         int len = to - from;
    23         int[] array = new int[len + 1];
    24         for (int i = 0; i <= len; i++) {
    25             array[i] = from + i;
    26         }
    27         return sumAll(array);
    28     }
    29 }