Guest User

Untitled

a guest
Jan 17th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. int[] listaA = {2, -5, -121, 102, -35, -2, 0, -125, 802, -10};
  2. int[] listaB = {6, 99, -1, 12, 1, -2};
  3. int[] novoVetor;
  4.  
  5. novoVetor = new int[listaA.length + listaB.length]; // tamanha do vetor A e o tamanho do vetor B
  6. int nr_vetorB = listaA.length, rep=0, g=0;
  7.  
  8. for (int i = 0; i < listaA.length; i++) {
  9. novoVetor[i] = listaA[i];
  10. }
  11. for (int j = 0; j < listaB.length; j++) {
  12. novoVetor[nr_vetorB] = listaB[j];
  13. nr_vetorB++;
  14. }
  15.  
  16.  
  17. for (int x = 0; x < novoVetor.length; x++) {
  18. while( g < novoVetor.length) {
  19. for (int y = 1; y < novoVetor.length; y++) {
  20. if (novoVetor[x] == novoVetor[y]) {
  21. g = novoVetor.length;
  22. rep++;
  23. } else {
  24. g++;
  25. }
  26.  
  27.  
  28. }
  29.  
  30. }
  31. System.out.print(" " +novoVetor[x]);
  32. }
  33.  
  34. System.out.print("nElementos repetidos:" +rep);
  35.  
  36. int[] listaA = {2, -5, -121, 102, -35, -2, 0, -125, 802, -10};
  37. int[] listaB = {6, 99, -1, 12, 1, -2};
  38. int[] todos = new int[listaA.length+listaB.length];
  39.  
  40. int pt = 0;
  41. for(int i : listaA){
  42. todos[pt] = i;
  43. pt++;
  44. }
  45. for(int i : listaB){
  46. todos[pt] = i;
  47. pt++;
  48. }
  49.  
  50. int total = 0;
  51. for(int ptA=0; ptA < todos.length; ptA++){
  52. for(int ptB=0; ptB < todos.length; ptB++){
  53. if(ptA == ptB){ // se os ponteiros forem iguais desconsidera..
  54. continue;
  55. }
  56. if(todos[ptA] == todos[ptB]){
  57. total++;
  58. }
  59. }
  60. }
  61.  
  62. total = (total/2); /// pois irá comparar o mesmo item 2 vezes..
  63. System.out.println("Elementos repetidos: "+total);
Add Comment
Please, Sign In to add comment