java - Finding a cumulative frequency array -


this method converts frequency array cumulative frequency array. example if initial array { 1, 2, 3, 4} calling method should give { 1, 3, 6, 10}

this ive written:

public void cumulate(int[] a) {    (int i= 0; < a.length; ++){           a[i] = a[i-1] + a[i];     } } 

i'm wrong, need generating set of codes. if able assist me, lovely!

well you're going outside array = 0. start 1:

public void cumulate(int[] a) {    (int = 1; < a.length; i++){           a[i] = a[i - 1] + a[i];     } } 

should ok now.


Comments