logo Practice-It logo

BJP4 Self-Check 10.16: ArrayListMystery2

Language/Type: Java ArrayList Collections mystery
Author: Marty Stepp (on 2016/09/08)

Consider the following method:

public static void mystery2(ArrayList<Integer> list) {
    for (int i = list.size() - 1; i >= 0; i--) {
        if (i % 2 == 0) {
            list.add(list.get(i));
        } else {
            list.add(0, list.get(i));
        }
    }
    System.out.println(list);
}

Write the output produced by the method when passed each of the following ArrayLists:

[10, 20, 30]
[8, 2, 9, 7, 4]
[-1, 3, 28, 17, 9, 33]

You must log in before you can solve this problem.


Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.