Pessoa, preciso criar um conjunto união a partir de dois vetores e não estou conseguindo. Confesso que estou com um pouco de dificuldade para transferir os elementos de um array maior para um menor.
import javax.swing.JOptionPane;
public class Exercício6 {
public static void main(String[] args) {
int vetorA[] = new int[5];
int vetorB[] = new int[5];
String numeroA, numeroB;
int valorNumeroA, valorNumeroB, soma = 0;
for (int i = 0; i < vetorA.length; i++) {
numeroA = JOptionPane.showInputDialog("Digite um número para acrescentar no PRIMEIRO vetor");
valorNumeroA = Integer.parseInt(numeroA);
vetorA[i] = valorNumeroA;
}
for (int i = 0; i < vetorB.length; i++) {
numeroB = JOptionPane.showInputDialog("Digite um número para acrescentar no SEGUNDO vetor");
valorNumeroB = Integer.parseInt(numeroB);
vetorB[i] = valorNumeroB;
}
int vetorA[] = new int[soma];
for (int i = 0; i < vetorB.length; i++) {
for (int j = 0; j < vetorA.length; j++) {
for (int k = 0; k < vetorC.length; k++) {
if (vetorB[i] == vetorA[j]) {
soma++;
vetorC[j] = vetorB[i];
}
}
}
}
for (int i = 0; i < vetorC.length; i++) {
System.out.println(vetorC[i]);
}
}
}