Maya Maya - 3 months ago 6x
Java Question

How to multiply array of doubles in another double?

I'm new to this site, and am working on a school assignment, but got stuck.

I was wondering if there is any way to multiply a

double []array
by a

for(int i = 0; i <= speed.length; i++)
double [] mph = speed[i] * 1.15;

That is my code, but when I compile it in java, it says:

"Incompatible types: double cannot be converted to double[]"

How do I fix this?


You are almost there: you need to be a little more specific about where the result of the operation is going to be stored...

you have the Array speed so yo can use this to store directly the result...

for example:

for(int i = 0; i < speed.length; i++)
    speed[i] = speed[i] * 1.15;

you can define a new array... like the one named mph, just be careful with the size of the new one... and then do:

double mph[] = new double[speed.length];
for(int i = 0; i < speed.length; i++)
    mph[i] = speed[i] * 1.15;