How divide all items in an array by a double?

java

Solution

All you need to do is specify an index for your normal array like so, and make sure to initialize normal:

double[] normal = new double[v.length];
for(int a = 0; a < v.length; a++)
{
  normal[a] = v[a]/sum;
}

Assuming that your sum is correct. I believe this should work.

Problem

I am a complete beginner at this and I have a little problem with an array. The point of this program is to calculate the normalization of a vector. The first part just calculates the length of the array into the int called sum and then I want to divide all the items in the array v with this sum. normal[] = v[a]/sum; this line is clearly the issue, but how should I do this?? ``` public static double[] normalized(double[] v){ double sum = 0; for(int counter = 0; counter < v.length; counter++){ sum += Math.pow(v[counter], 2); } sum = Math.sqrt(sum); double[] normal; for(int a = 0; a < v.length; a++){ normal[] = v[a]/sum; } return normal; } ```

Original source