samples/composition/src-api2.0/api/Arithmetica.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:51:04 +0200
changeset 17 af005434d27f
child 20 afae7be94b25
permissions -rw-r--r--
Converting to ant freeform script as it allows to demonstrate the amoeba effect
jtulach@17
     1
package api;
jtulach@17
     2
jtulach@17
     3
/** Class to simplify arithmetical operations.
jtulach@17
     4
 *
jtulach@17
     5
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jtulach@17
     6
 */
jtulach@17
     7
public class Arithmetica {
jtulach@17
     8
    public int sumTwo(int one, int second) {
jtulach@17
     9
        return one + second;
jtulach@17
    10
    }
jtulach@17
    11
    
jtulach@17
    12
    public int sumAll(int... numbers) {
jtulach@17
    13
        int sum = numbers[0];
jtulach@17
    14
        for (int i = 1; i < numbers.length; i++) {
jtulach@17
    15
            sum = sumTwo(sum, numbers[i]);
jtulach@17
    16
        }
jtulach@17
    17
        return sum;
jtulach@17
    18
    }
jtulach@17
    19
    
jtulach@17
    20
    public int sumRange(int from, int to) {
jtulach@17
    21
        return (from + to) * (from - to + 1) / 2;
jtulach@17
    22
    }
jtulach@17
    23
}