Create a method removeEvens that removes all even elements from an ArrayList of Integers. The method should also print all the remaining items in the ArrayList.

Once the method is created, call it on the existing ArrayList in the main method.
Someone please help im really confused

Respuesta :

Answer:

import java.util.ArrayList;

public class Odds {

public static void main(String[] args) {

ArrayList<Integer> odds = new ArrayList<Integer>();

for (int index = 1; index < 101; index++) {

odds.add(index);

}

removeEvens(odds);

System.out.println(odds);

}

public static void removeEvens(ArrayList<Integer> array) {

for (int i = 0; i < array.size(); i++) {

if (array.get(i) % 2 == 0) {

array.remove(i);

i--;

}

}

}

}