Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int[] listaA = {2, -5, -121, 102, -35, -2, 0, -125, 802, -10};
- int[] listaB = {6, 99, -1, 12, 1, -2};
- int[] novoVetor;
- novoVetor = new int[listaA.length + listaB.length]; // tamanha do vetor A e o tamanho do vetor B
- int nr_vetorB = listaA.length, rep=0, g=0;
- for (int i = 0; i < listaA.length; i++) {
- novoVetor[i] = listaA[i];
- }
- for (int j = 0; j < listaB.length; j++) {
- novoVetor[nr_vetorB] = listaB[j];
- nr_vetorB++;
- }
- for (int x = 0; x < novoVetor.length; x++) {
- while( g < novoVetor.length) {
- for (int y = 1; y < novoVetor.length; y++) {
- if (novoVetor[x] == novoVetor[y]) {
- g = novoVetor.length;
- rep++;
- } else {
- g++;
- }
- }
- }
- System.out.print(" " +novoVetor[x]);
- }
- System.out.print("nElementos repetidos:" +rep);
- int[] listaA = {2, -5, -121, 102, -35, -2, 0, -125, 802, -10};
- int[] listaB = {6, 99, -1, 12, 1, -2};
- int[] todos = new int[listaA.length+listaB.length];
- int pt = 0;
- for(int i : listaA){
- todos[pt] = i;
- pt++;
- }
- for(int i : listaB){
- todos[pt] = i;
- pt++;
- }
- int total = 0;
- for(int ptA=0; ptA < todos.length; ptA++){
- for(int ptB=0; ptB < todos.length; ptB++){
- if(ptA == ptB){ // se os ponteiros forem iguais desconsidera..
- continue;
- }
- if(todos[ptA] == todos[ptB]){
- total++;
- }
- }
- }
- total = (total/2); /// pois irá comparar o mesmo item 2 vezes..
- System.out.println("Elementos repetidos: "+total);
Add Comment
Please, Sign In to add comment