1

This is my code:

public  float[] DataSet() {
  float[] Data = {1.51,2.35,3.36};
  return  Data;}

Why do I get the error message:

This method must return a result of type float[]

2 Answers 2

2

The literals, 1.51 etc. are implicitly double. That's how Java interprets them.

See Primitive data types in Java.

If you want a float array, try postfixing them with f.

float[] Data = {1.51f, 2.35f, 3.36f};

Sign up to request clarification or add additional context in comments.

Comments

0

The values inside array are doubles. You could for example do this:

public float[] DataSet() {
    float[] Data = {1.51f,2.35f,3.36f};
    return  Data;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.