I have an array of random size filled with random numbers (between 0 and 3). I need to sort a position inside it and from that position, pick up the numbers "above" and "below" from the selected position and save it to another array, making a copy.
So far I have done this but I do not know exactly how to select the "cut" position:
public static void main(String[] args) {
//(1) cria o array "a" e o preenche com uma sequência de números aleatórios
Random gerador = new Random(); // tamanho do vetor com as posições do agente
Random numeros = new Random(); // direções que o agente tomará
Random rnd = new Random(); // posição de corte do vetor
int aux = gerador.nextInt(11);
int [] a = new int[aux];
int [] v = new int[aux];
for (int i=0; i < a.length; i++) {
a[i]= numeros.nextInt(4);
System.out.println("a[" + i + "]=" + a[i]);
}
System.out.println();
//(2) Copia o conteúdo de "a" para "b" com o uso de laço for
int [] b = new int[a.length]; //primeiro é preciso reservar espaço para b
for (int i=0; i < a.length; i++) b[i]=a[i]; //agora podemos copiar
//(3) exibe o conteúdo de "b"
for (int i=0; i < a.length; i++) {
System.out.println("b[" + i + "]=" + b[i]);
int j =0;/*
v[j]= numeros.nextInt(b.length);
}
System.out.println(v);*/
int x=0;
int [] s = new int[x];
x = rnd.nextInt(i);
s[j] = x;
System.out.println(s);
}
PS: This is for a genetic algorithm job, so view the vector as an agent. After the cut, I will have to cross with another vector similar to itself, but with different positions.