The first method should reset sumTwo
to zero in every iteration. Currently it accumulates values from one execution of the outer loop to the next. Otherwise it's OK.
Alternatively, and more efficiently, you could notice that the difference between the sumTwo
of one iteration and the next is the new array element. This means you don't need the inner loop.
for(int i = 0; i < arrayOfElements.length; i++) {
sumTwo = sumTwo + arrayOfElements[j];
sum = sum + Math.pow(sumTwo, 2);
}
The second method is supposed to return the index of the element with maximum absolute value, not the element itself. Note the subindex i in max.