Skip to content
Snippets Groups Projects
Commit c93d79a3 authored by Melina Väkiparta's avatar Melina Väkiparta
Browse files

Upload New File

parent e5441272
No related branches found
No related tags found
No related merge requests found
import java.util.ArrayList;
import java.util.List;
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