area = width * height
XX=YY*ZZ area width height
20=10*2 area width height
300=20*15 area width height
area width height= *
z = 10 + (3*x) + j
class Accumulator { constructor() { //Initialize instance var this.result = 0; } increaseBy(amount) { let newResult = this.result + amount; this.result = newResult; } getResult() { return this.result; } } //--------------------------------- class AccumulatorTest { test1() { let accumulator = new Accumulator(); let array = [10, 20, 30, 40]; for (let nextNumber of array) accumulator.increaseBy(nextNumber); console.log("Result: " + accumulator.getResult()); } } //--------------------------------- let test = new AccumulatorTest(); test.test1();
public class Accumulator { private int result = 0; public Accumulator() { this.result = 0; } public void increaseBy(int amount) { int newResult = this.result + amount; this.result = newResult; } public int getResult() { return this.result; } public static void main(String[] args) { Accumulator accumulator = new Accumulator(); int[] array = new int[] {10, 20, 30, 40}; for (int nextNumber: array) accumulator.increaseBy(nextNumber); System.out.println("Result: " + accumulator.getResult()); } }