I have some questions about vectors and functions.
public class teste{
/*Função que retorna um vetor de inteiros com números aleatórios*/
public static int [] vetorFuncao(){
int numerosAleatorios [] = new int[10];
for(int i=0;i<10;i++){
numerosAleatorios[i] = ( (int) (Math.random()*10) )+1;
}
return numerosAleatorios;
}
/*Principal*/
public static void main(String[]args){
int [] vetor = vetorFuncao();
}
}
I know that to create a vector one must inform the number of positions.
Ex: int [] vetor = new int [10];
However, int [] vetor = vetorFuncao();
does not need to specify the position quantity, since the number of positions will be equal to the number of positions of vetorFuncao();
Why do not you need to specify the number of positions of the int [] vetor = vetorFuncao()
vector when I create a vector that gets a given function that returns an integer vector.
int [ ] vetor = new int [x];
You need to specify x
;
int [] vetor = vetorFuncao();
Do not specify, since vetor.lenght
will equal vetorFuncao();