Skip to content
Snippets Groups Projects
Commit 8a2a75ec authored by Emilia Valtomäki's avatar Emilia Valtomäki
Browse files

Upload New File

parent 25d1ed43
No related branches found
No related tags found
No related merge requests found
import java.util.ArrayList;
public class KorjaaMinut {
//"kutsu metodi"
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);
}
/*"suorittava metodi",
kuuluu kohtaan poistaNegatiiviset(lista); "kutsu metodissa"
*/
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++;
}
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment