Advertisement
Guest User

Comprobar repetidos e indicar posiciones

a guest
Jun 19th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. public void muestraRepetidos(int array[]) {
  2.  
  3. int cuentaPosición = 0;
  4.  
  5. ArrayList<Integer> valor = new ArrayList<Integer>();
  6.  
  7. ArrayList<ArrayList<Integer>> posición = new ArrayList<ArrayList<Integer>>();
  8.  
  9. for (int i = 0; i < array.length - 1; i++) {
  10.  
  11. if (!valor.contains(array[i])) {
  12.  
  13. valor.add(array[i]);
  14.  
  15. posición.add(new ArrayList<Integer>());
  16.  
  17. }
  18.  
  19. }
  20.  
  21. for (int j = 0; j < array.length - 1; j++) {
  22.  
  23. for (int k = j + 1; k < array.length; k++) {
  24.  
  25. if (array[j] == array[k]) {
  26.  
  27. System.out.println("Posición: " + j);
  28.  
  29. posición.get(j).add(k);
  30.  
  31. } else {
  32.  
  33. break;
  34. }
  35.  
  36. }
  37.  
  38. }
  39.  
  40. System.out.println(valor);
  41. System.out.println("Tamaño lista valor " + valor.size() + " y lista posición " + posición.size());
  42.  
  43. for (int par = 0; par < valor.size(); par++) {
  44.  
  45. System.out.println("A " + valor.get(par) + " P " + posición.get(par));
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement