samples/composition/src-api2.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 23 e043859ed1ca
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, 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     }
    13     
    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     }
    21     
    22     public int sumRange(int from, int to) {
    23         return (from + to) * (to - from + 1) / 2;
    24     }
    25 }