So i'm working on a problem that focuses on taking the cumulative sum of an array so for example if i have an array of ({0,2,3,-1,-1}) it returns {0,2,5,4,3}... or if you have an array of [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] it should return [1, 3, 6, 10, 15, 21, 28, 36, 45, 55]...
Right now i'm struggling with two problems one i have to use the method given and i'm struggling with what to return because total will not.. To my code i know it works for adding up the sum of an array but not the cumulative sum as in my examples.. any guidelines would be helpful.
public int[] makeCumul(int[] in) {
int[] out = { in.length };
int total = 0;
for (int i = 0; i < out.length; i++) {
total += out[i];
}
return total;
}
in
. That seems problematic.int[]
but you're returning anint
.out
as a size 1 array. 2) Your method sig says you return anint[]
but you're actually returning an int. 3) You never actually read any of the values in the input array.