0
public double[] add (double[] u, double[] v) 
{
    double[] output = new double[u.length];

    for(int i = 0; i < u.length; i++)
    {
        output[i] = u[i] + v[i];
    }
    return output;
}
public double dotProduct(double[] u, double[] v) 
{
    double output = 0.0;

    for(int i = 0; i < u.length; i++)
    {
        output += u[i] * v[i];
    }

    return output;
}
public double[] scalarProduct (double alpha, double[] v) 
{
    double[] output = new double[v.length];

    for(int i = 0; i < v.length; i++)
    {
        output[i] = v[i] * alpha;
    }

    return output;
}
public double norm (double[] v) 
{
    return 0;
}

Hi, I am trying to add two vectors but when I run it it gives me this error:

Can you recognize why it is printing NullPointException error?

in add method, double[] output = new double[u.length]; has NullPointerException.

Eric
  • 159
  • 14

0 Answers0