Error returning vector in a method

Asked

Viewed 24 times

1

I can not return the predictions vector, Android Studio is not accepting. (incompatible Types)

public double MediaMovelSimples(double[] valores) {

    int i;
    int j;

    double[] previsoes = new double[valores.length - 3];

    int parametro = 0;

    for (i = 0; i < valores.length - 3; i++) {

        for (j = parametro; j < parametro + 3; j++) {

            previsoes[i] += valores[j];
        }
        parametro+=1;
    }
    return previsoes;
}
  • What error appears? ask the question

  • incompatible Types

  • How do you want to return a vector of double if your method signature returns only one double?

2 answers

3


the problem is that you are creating a method of type double and is returning an array of double change

public double MediaMovelSimples(double[] valores) {

for

public double[] MediaMovelSimples(double[] valores) {
  • I get it. Thank you!

  • If you’ve cleared your doubts please close the question

1

Here public double MediaMovelSimples(double[] valores) you declare and here double[] previsoes, the two statements have to be equal. That’s what the error is saying incompatible types.

Browser other questions tagged

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