Adding integers of array upto some number (java)
<p>I have a java question.</p>

<p>I have two <code>int[]</code> arrays: <code>cdn</code> and <code>cmn</code>.<BR>
<code>cdn</code> is <code>{1,1,1,1,1,1,2,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}</code> <BR>
<code>cmn</code> is <code>{8,8,16}</code><BR>
I need a program that adds the consecutive integers of <code>cdn[]</code> upto <code>cmn[init]</code> and returns the number of integers used in the addition. Then it continues adding from the next integer of <code>cdn[]</code> upto <code>cmn[init+1]</code> and return the number of integers. For the arrays above this is done 3 times: the first time the return value is 7, the second time it is 7, and the third time it is 16. The number of integers can be collected in and <code>int[]</code> which is <code>{7,7,16}</code>. The code I have is:</p>

<pre class="lang-java prettyprint-override"><code>int numofints = 0;
int init = 0;
int plus = 0;
while(init &lt; m2){
 for(int j = 0; j &lt; cdn.length; j++){
    plus += cdn[j];
    numofints++;
  if(plus == cmn[init]){
   init++;
  }
 }
}
System.out.print(numofints);
</code></pre>

<p>in which <code>m2</code> is the size of <code>cmn</code>, which is 3 in this case. Note that my program starts to loop from the beginning of <code>cdn</code> over and over again, because <code>j = 0</code>. I want it to start where it ended the previous time!
I hope you have a solution for me.</p>

<p>Bjorn</p>
