Loop Apocalypse
String Nightmares
ArrayList Doom
Recursion Madness
AP Exam Trickery
100

int sum = 0;

for (int i = 1; i <= 4; i++) {

    sum += i;

}

What is the value of sum?

10

100

String s = "computer";

System.out.println(s.substring(2,5));

What will be printed?

mpu

100

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

list.add(3);

list.add(5);

list.add(7);

list.remove(1);

What remains in the ArrayList?

[3, 7]

100

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


for (int i = 1; i <= 5; i++) {

    list.add(i);

}


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

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

        list.remove(i);

    }

}

What is f(4)?

10

100

int[] arr = new int[4];

System.out.println(arr[2]);

What prints?

0

200

Nested loop tracing: What prints?

for (int i = 0; i < 3; i++) {

 for (int j = 0; j < 2; j++) {

  System.out.print(i + j);

 }

}

011223

200

String s = "banana";

System.out.println(s.indexOf("a"));

1

200

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

list.add(2);

list.add(4);

list.add(6);

list.set(1,9);

What is in the list after the code runs?

[2, 9, 6]

200

public static void mystery(int n) {

    if (n == 0) return;

    System.out.print(n);

    mystery(n - 1);

}

What prints when mystery(3) is called?

321

200

String s = "hello";

System.out.println(s.charAt(5));

What happens?

StringIndexOutOfBoundsException

300

int count = 0;

for (int i = 1; i <= 3; i++) {

    for (int j = i; j <= 3; j++) {

        count++;

    }}

What is the final value of count?

6

300

String a = "hi";

String b = new String("hi");

System.out.println(a == b);

What will be printed?

false

300

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

list.add(1);

list.add(2);

list.add(3);


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

    list.remove(i);

}

What remains in the list?

[2]

300

public static int f(int n) {

    if (n <= 1) return 1;

    return n * f(n - 1);

}

What is f(5)?

120

300

int[][] grid = {

    {1,2,3},

    {4,5,6}

};

What is grid.length?

2

400

While loop: What is the final value of x?

int x = 0;

while (x < 10) {

  x += 3;

}

12

400

String s = "abcdefgh";

System.out.println(s.substring(3));

What prints?

defgh

400

ArrayList<String> list = new ArrayList<>();

list.add("A");

list.add("B");

list.add(1,"C");

What is in the list?

[A, B, C]

400

public static String reverse(String s) {

    if (s.length() == 0)

        return s;

    return reverse(s.substring(1)) + s.charAt(0);

}

What is reverse("code")?

edoc

400

int[][] grid = {

    {1,2,3},

    {4,5,6}

};

What is grid[0].length?

3

500

for (int i = 1; i <= 3; i++) {

    for (int j = 1; j <= i; j++) {

        System.out.print("*");

    }

}

How many stars will print?

6

500

String s = "racecar";

System.out.println(s.substring(2,6));

What prints?

ceca

500

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

for (int i = 1; i <= 5; i++) {

    list.add(i);

}

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

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

        list.remove(i);

    }

}

What is in the resulting ArrayList?

[1, 3, 5]

500

public static int mystery(int n) {

    if (n == 0) return 0;

    return 1 + mystery(n / 2);

}

What is mystery(8)?

4

500

int x = 5;

System.out.println(x++ + ++x);

What prints?


12

M
e
n
u