logo CodeStepByStep logo

arrayListMystery4

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

public static void mystery(ArrayList<Integer> list) { 
    for (int i = list.size() - 1; i > 0; i--) { 
        if (list.get(i) < list.get(i - 1)) { 
            int n = list.get(i); 
            list.remove(i); 
            list.add(0, n); 
        } 
    } 
    System.out.println(list);
} 
[2, 6, 1, 8]
[10, 30, 40, 20, 60, 50]
[-4, 16, 9, 1, 64, 25, 36, 4, 49]

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.