So:
float[] floatArray = new float[]{1.0f, 2.2f, 3.4f};
vetorFloat(floatArray);
So the method and class in static context would look like this:
class main {
public static void main(String[] args) {
float[] floatArray = new float[]{1.0f, 2.2f, 3.4f};
vetorFloat(floatArray );
}
private static float vetorFloat(float[] vetor) {
//algum código
return vetor[x];
}
}
Except that X in return vetor[x];
will give compilation problem. It needs to be solved. It may look like this:
class Main {
public static void main(String[] args) {
float[] floatArray = new float[]{1.0f, 2.2f, 3.4f};
vetorFloat(floatArray );
}
private static float vetorFloat(float[] vetor) {
int x = 0;
return vetor[x];
}
}
Now your method will return the first position of the last array.
The way you did, you're passing an element of the array, not the whole array. In my example, I declare a new array and I already fill it in. So the variable floatArray
represents the entire array and if I do floatArray[0]
, I'm only accessing the first element of the array, which in this case is 1.0.
That "F" there next in the number, it is useful for Java to know that it is a type float
. When you fill in an arbitrated number in the code, java does not know if it treats as int
, float
, long
... then you specify after declaring the number. Examples:
-
long 0L
-
float 0.0f
-
double 0.0d
See official documentation on primitive types . It can help a lot.