Trace Me If You Can
Class Act
Array Potter and the Index of Secrets
Fast & Curious: Algorithm Drift
A Bug's Life
100

int x = 4;
x += 3;
System.out.println(x * 2);

What is 14?

100

This is the purpose of a constructor in a Java class.

What is to initialize a new object when it is created?

100

int[] nums = {3, 6, 9, 12};
System.out.println(nums[2]);

What is 9?

100

This is what a linear search does.

What is that it checks elements one at a time until it finds the target or reaches the end?

100

There's something wrong with this code:
if (x = 5)

What is that it should use ==?

200

int total = 0;
for (int i = 1; i <= 4; i++)
{
    total += i;
}
System.out.println(total);

What is 10?

200

This is the difference between an instance variable and a local variable? 

What is an instance variable belongs to an object and is declared in the class and a local variable is declared inside a method or block and only exists there?

200

ArrayList<String> names = new ArrayList<String>();
names.add("Ana");
names.add("Ben");
names.add(1, "Cara");
System.out.println(names);

What is [Ana, Cara, Ben]?

200

The algorithm finds the smallest element and swap it with the first element, then find the second smallest and swap it with the second element, and keep doing this until all elements are moved to correct position.

What is Selection Sort?

200

There's something wrong with this code:
for (int i = 0; i <= arr.length; i++)
{
    System.out.println(arr[i]);
}

What is that the loop goes out of bounds?

300

String word = "computer";
System.out.println(word.substring(1, 4));

What is omp?

300

When multiple methods have the same name but different parameter lists.

What is method overloading?

300

int[][] grid = {{1, 2, 3}, {4, 5, 6}};
System.out.println(grid[1][2]);

What is 6?

300

This condition must be true before binary search can be used.

What is the data must be sorted?

300

int result = 7 / 2;
System.out.println(result);
This is the output of result.

What is 3?

400

public static int mystery(int n)
{
    if (n == 1)
    {
        return 1;
    }
    return n + mystery(n - 1);
}
This is returned by mystery(4).

What is 10?

400

public class Student
{
    private String name;
    private int grade;
    public Student(String n, int g)
    {
        name = n;
        grade = g;
    }
    public String getName()
    {
        return name;
    }
    public int getGrade()
    {
        return grade;
    }
}
The part of the code creates and initializes a new Student object.

What is public Student(Sting n, int g)?

400

int[] nums = {2, 4, 6};
for (int n : nums)
{
    n = n * 2;
}
System.out.println(nums[1]);

What is 4?

400

This sorting algorithm is generally faster for a large sorted list.

What is Binary search?

400

int[] a = {1, 2, 3};
int[] b = a;
b[0] = 99;
System.out.println(a[0]);
This is the output.

What is 99?

500

int count = 0;
for (int i = 0; i < 3; i++)
{
    for (int j = i; j < 3; j++)
    {
        count++;
    }
}
System.out.println(count);

What is 6?

500

There is something wrong with this statement: "A static variable and an instance variable are basically the same because objects can use both."

What is static belongs to the class and non-static belongs to each object?

500

ArrayList<Integer> nums = new ArrayList<Integer>();
nums.add(1);
nums.add(2);
nums.add(3);
nums.add(4);
for (int i = 0; i < nums.size(); i++)
{
    if (nums.get(i) % 2 == 0)
    {
        nums.remove(i);
    }
}
System.out.println(nums);
This is the output.

What is [1, 3]?

500

This is the difference between a array and ArrayList in Java?

What is that ArrayList can be changed?

500

String a = "hello";
String b = new String("hello");
if (a == b)
    System.out.println("same");
else
    System.out.println("different");
This is the output.

What is different?

M
e
n
u