mac->arch

This commit is contained in:
eslusarz
2026-05-19 13:42:21 +02:00
parent 646f4dc077
commit 30b66dd99b
305 changed files with 1617 additions and 31630 deletions
+35
View File
@@ -0,0 +1,35 @@
package parziale.p231110;
import java.util.Map;
import java.util.HashMap;
public class Esercizio {
/*
* Scrivere un metodo generico statico che prende in input
* un array di elementi e restituisce il
* numero di oggetti presenti allinterno dellarray che
* non presentano duplicazioni. Quindi
* utilizzare il metodo sul tipo Integer.
* Esempio: se larray fosse {10, 6, 5, 6, 7, 8, 6, 8, 10, 12, 10},
* il metodo dovrebbe restituire
* lintero 3 (in grassetto i 3 elementi che non presentano duplicazioni).
*/
public static int numeroOccorrenzeSingole(int[] array) {
if (array == null) throw new NullPointerException();
Map<Integer, Integer> lista = new HashMap<Integer, Integer>();
for (Integer i : array) {
if (lista.get(i) == null) lista.put(i, 1);
else lista.put(i, lista.get(i) + 1);
}
int counter = 0;
for (Integer i : lista.keySet()) {
if (lista.get(i) == 1) counter++;
}
return counter;
}
}