dynamic cumulation in ArrayList using java

Hi,

See the Below example, I added the values in ArrayList.These values I am fetching in loop. These iterator values I want to get it cumulative way. Values are dynamic. I am expecting the result like below

Actual valuecumulative value

10 10

20 30(10+20)

30 60(30+30)

50 110(60+50)

80 190(80+110) like result I am expecting.

Please see the below code and change if any modification required.

int value;

int A1=30;

int A2=300;

int B1=40;

int B2=400;

int C1=20;

int C2=200;

int D1=10;

int D2=100;

int tots=A1+A2;

int tot = 0;

int to = 0;

Bean b=new Bean();

ArrayList al=new ArrayList();

al.add(new Integer(A1));

al.add(new Integer(B1));

al.add(new Integer(C1));

al.add(new Integer(D1));

Iterator it=al.iterator();

for(int i=0;i<al.size();i++){

b.setObjValue(al.get(i));

Integer k=(Integer) b.getObjValue();

System.out.println(b.getObjValue()+" -- "+k );

double d=0;

d=d+k;

}

Awating for any + ve response with result.>

[1142 byte] By [sanjeevysa] at [2007-11-27 2:10:16]
# 1
Just declare an int variable before your for loop called, for example, int lastIntValue = 0;Then at the end of your for block just add the result of lastIntValue to the current element retrieved from your ArrayList.
maple_shafta at 2007-7-12 2:02:03 > top of Java-index,Java Essentials,Java Programming...