Explore what CodeHS has to offer for districts, schools, and teachers.
Click on one of our programs below to get started coding in the sandbox!
View All
Given the following code segment, what will the output be?
ArrayList<Integer> list = new ArrayList<Integer>(); list.add(5); list.add(8); list.add(1); list.add(4); list.add(3); int counter = 0; while(counter < list.size()) { if (list.get(counter) % 2 == 0){ list.set(counter, 0); } counter++; } System.out.println(list.toString());
[5, 8, 1, 4, 3]
[5, 0, 1, 0, 3]
[0, 8, 0, 4, 0]
[8, 4]
An IndexOutofBoundsException occurs.
IndexOutofBoundsException