array_summation.mj 634 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
class Summator {

    public int sum(int[] array, int len) {
        int sum = 0;
        int i = 0;
        while(i < len) {
            sum = sum + array[i];
            i = i + 1;
        }
        return sum;
    }

    public static void main(String[] args) {

        Summator acc = new Summator();

        int arrayLen = System.in.read();
        int[] array = new int[arrayLen];

        int i = 0;
        while(i < arrayLen) {
            array[i] = System.in.read();
            i = i + 1;
        }

        int arraySum = acc.sum(array, arrayLen);
        System.out.write(arraySum);
        System.out.flush();
    }
}