ChatCrawlersearch across public Telegram Open the app
J

Java Studio

26 October 2017
2017-10-26×
26 October 2017
J
lo que encuentre comparto
R
Hola!!! Una pregunta, para saber si en un array hay números repetidos?? Yo lo he hecho con un bucle for en los qué comparo elemento[i] con elemento[i+1], cuándo es igual aumento un contador, pero hay elementos repetidos y no funciona cómo debería, alguien sabe una forma mejor de hacerlo??
I
Si los elementos repetidos deben estar contiguos funcionaria ........... Pero para hallar repetidos deberías comparar el primer elemento con todo el array
R
A ver si funcionase
R
es decir haces un primer for para ir elemento por elemento y despues dentro de ese primer for haces otro for para recorrer todo el array para haber si lo hay repetido
Con un for: desde la posicion cero hasta la posicion igual a su tamaño
D
for i=0; i < array.lenght; i++
R
No sé por qué ha salido la imagen del revés
R
Entonces comparo matriz[i] con matriz [z] entiendo no??
I
public static void diferencia(LinkedList<Integer> l1,LinkedList<Integer> l2){ HashSet<Integer> hs1=new HashSet<Integer> (); HashSet<Integer> hs2=new HashSet<Integer> (); HashSet<Integer> hs3=new HashSet<Integer> (); hs1.addAll(l1); hs2.addAll(l1); hs1.removeAll(l2); hs2.removeAll(hs1); hs3.addAll(l1); hs3.addAll(l2); hs3.removeAll(hs2); System.out.println(hs3); } public static void main(String[] args) { LinkedList<Integer> l1=new LinkedList<Integer> (); LinkedList<Integer> l2=new LinkedList<Integer> (); l1.add(0); l1.add(3); l1.add(2); l1.add(10); l1.add(-4); l1.add(3); l2.add(3); l2.add(7); l2.add(-10); l2.add(-4); l2.add(1); diferencia(l1,l2);
no se como quitarlos
Sr. IQue cuqui
public static void diferencia(LinkedList<Integer> l1,LinkedList<Integer> l2){ HashSet<Integer> hs1=new HashSet<Integer> (); HashSet<Integer> hs2=new HashSet<Integer> (); HashSet<Integer> hs3=new HashSet<Integer> (); hs1.addAll(l1); hs2.addAll(l1); hs1.removeAll(l2); hs2.removeAll(hs1); hs3.addAll(l1); hs3.addAll(l2); hs3.removeAll(hs2); System.out.println(hs3); } public static void main(String[] args) { LinkedList<Integer> l1=new LinkedList<Integer> (); LinkedList<Integer> l2=new LinkedList<Integer> (); l1.add(0); l1.add(3); l1.add(2); l1.add(10); l1.add(-4); l1.add(3); l2.add(3); l2.add(7); l2.add(-10); l2.add(-4); l2.add(1); diferencia(l1,l2);
I
Стикер
sticker.webp · 35 KB · click to show
👍
A
Soy al único al que le cuesta seguir esa solución?
I
Para mí las colecciones ya sean listas o maps solucionan mucho respecto a manejar datos
Calendar: October 2017
Archive by month
Open in Telegram Каталог площадок Искать в ChatCrawler

A snapshot of an open public feed from the search index ChatCrawler — “Google for public Telegram”; refreshed as the venue is crawled. Times are UTC.

Public content only, official Telegram API. About · FAQ · What we do not do · Remove a page · Catalog