How to return a vector to another vector in Java?

Asked

Viewed 259 times

0

I’m doing a program that applies hill climbing, but the value I need to compare to see if the previous one is better than the next one is a vector double

My method to find the best value returns an array double:

public double[] método(parâmetros){

   código

   return vetor;

}

What I’m not able to do is assign this vector to another vector:

public void método2(parâmetros){

   double vet2[] = new double[n];

   vet2[]=método(parâmetros);

}

My question is how I could return the vector and pass its values to another vector in another method?

  • If the best value is only 1 why return a double vector? And it would just be vet2 = método(parâmetros);

  • Thank you, that’s right.

  • Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site (when you have enough score).

2 answers

2

1

You’re trying to do the following:

vet2[]=método(parâmetros);

It’s like you’re trying to access a null position of the vet2.

To associate a new vector to the variable, simply name it, without brackets:

vet2=método(parâmetros);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.