int x = 4;
x += 3;
System.out.println(x * 2);
What is 14?
This is the purpose of a constructor in a Java class.
What is to initialize a new object when it is created?
int[] nums = {3, 6, 9, 12};
System.out.println(nums[2]);
What is 9?
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?
There's something wrong with this code:
if (x = 5)
What is that it should use ==?
int total = 0;
for (int i = 1; i <= 4; i++)
{
total += i;
}
System.out.println(total);
What is 10?
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?
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]?
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?
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?
String word = "computer";
System.out.println(word.substring(1, 4));
What is omp?
When multiple methods have the same name but different parameter lists.
What is method overloading?
int[][] grid = {{1, 2, 3}, {4, 5, 6}};
System.out.println(grid[1][2]);
What is 6?
This condition must be true before binary search can be used.
What is the data must be sorted?
int result = 7 / 2;
System.out.println(result);
This is the output of result.
What is 3?
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?
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)?
int[] nums = {2, 4, 6};
for (int n : nums)
{
n = n * 2;
}
System.out.println(nums[1]);
What is 4?
This sorting algorithm is generally faster for a large sorted list.
What is Binary search?
int[] a = {1, 2, 3};
int[] b = a;
b[0] = 99;
System.out.println(a[0]);
This is the output.
What is 99?
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?
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?
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]?
This is the difference between a array and ArrayList in Java?
What is that ArrayList can be changed?
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?