+ 1
Attempting a Sum Array
I am trying to recreate the array they told me to answer, but when I enter it all it gives me a error. Any ideas? package sample; public class Example { double sum = 0.0; int[] myArray = {10,20,25}; for(int x = 0; x < 4; x++){ sum+= myArray[x]; } System.out.println(sum); }
1 Respuesta
+ 4
x only has 3 elements, so x should be < 3 instead of < 4 in the for loop.