Reputation: 39
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[]
Upvotes: 1
Views: 1483
Reputation: 1181
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};
Upvotes: 2
Reputation: 591
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;
}
Upvotes: 0