ech.. specyficzne są te listy xd :D Jak mam zrobić warunek który mówi że mam policzyć ile liczb to liczby dodatnie i zarazem podzielne przez 3?
Wyskakuje mi błąd "NoSuchElementException" :/
public static void licz(List<Integer> lista)
{
ListIterator<Integer> itr = lista.listIterator();
int suma = 0, ile = 0;
while (itr.hasNext())
{
suma += itr.next();
if (itr.next() > 0 && itr.next() % 3 == 0)
ile++;
}
double srednia = (double) suma / lista.size();
System.out.println("1) Wyświetlam listę:\n\n" + lista + "\n\nSuma elementów listy: " + suma
+ "\nŚrednia elementów listy: " + srednia + "\nLiczba dodatnich elementów podzielnych przez 3: " + ile
+ "\n\nKoniec programu!");
}