-4

I am having problems with arrays.

I have written a code to add the sum of all the numbers in an array and I have to test it from the main by calling on previous arrays. But I can't figure out where I am going wrong.

 Scanner stdin = new Scanner(System.in);
    double [] scores = new double[5];
    System.out.println(scores.length);

for(int i = 0; i < scores.length; i++)
    {
        System.out.println("Please enter " + i + "th array value");
        scores[i] = stdin.nextDouble();
    }


 double sums = sumArray(scores);
    System.out.println(sums);

 }
public static double sumArray( double[] dArray)
{
    double sum = 0;
    for(int i = 0; i <= dArray.length; i++)
    {
        sum = sum + dArray[i];
    }
    return (sum);
}
}
cнŝdk
  • 31,391
  • 7
  • 56
  • 78

1 Answers1

2

This part

         for(int i = 0; i <= dArray.length; i++)

must be like

          for(int i = 0; i < dArray.length; i++)

If you share error, we can help much.

Semih Eker
  • 2,389
  • 1
  • 20
  • 29