Skip to content
Snippets Groups Projects
Commit 1554848e authored by Jasmin Lehtola's avatar Jasmin Lehtola
Browse files

Upload New File

parent cfa9d524
No related branches found
No related tags found
No related merge requests found
import java.util.ArrayList;
public class KorjaaMinut {
public static void main(String[] args) {
ArrayList<Integer> lista = new ArrayList<>();
lista.add(1);
lista.add(2);
lista.add(-1);
lista.add(3);
lista.add(-4);
lista.add(-5);
lista.add(6);
poistaNegatiiviset(lista);
System.out.println(lista);
}
public static void poistaNegatiiviset(ArrayList<Integer> lista) {
int indeksi = 0;
while (indeksi < lista.size()) {
int alkio = lista.get(indeksi);
if (alkio < 0) {
lista.remove(indeksi);
} else {
indeksi++;
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment