Conditionals
Loops
Variables
Operators
Arrays
100

What prints out from the following code?

int x = 5;
if (x <= 5) { System.out.println("hello"); }
else { System.out.println("world"); }



"hello"

100

Any for loop can be written as a while loop, T/F?

true

100

Declare an integer variable called "a" and initialize it to 5.

int a = 5;

100

the modulus operator

%

100
What is the first index of an array?

0

200

The next symbol in this code is:

if (x == 5)

{

200

Make the following into a for loop:

int i = 0;
while (i < 10) {
// code
i++;
}


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

// code

}

200

You can call methods on a String variable, T/F?

true

200

How to test if a number is even?

number % 2 == 0

200

How do you iterate through a 2D array?

Two nested for loops

300

Under what conditions does "orange" get printed?

if (x > 7) {
System.out.println("red");
} else {
System.out.println("orange");
}

when x <= 7

300

What is the syntax to declare a while loop that runs forever?

while (true) {

}

300

How do you print an array variable?

Iterate through it in a for loop, printing element by element

300

What is the difference between = and ==?

= is for assignment, == is for equality testing

300

How to reference the element at the 3rd row, 1st column of a 2D array?

array[2][0]

400

Name at least 2 syntax problems with this code.

if x == 6 {
System.out.println("apple")

parenthesis around condition, missing semicolon, missing closing bracket

400

Keyword that allows you to immediately halt execution of a loop

break

400

You can call methods on an int variable, T/F?

false

400

How to test two Strings for equality

.equals()

400

Declare and initialize a variable named "w" that is a new 2D array of Strings, with 4 rows and 5 columns.

String[][] w = new String[4][5];

500

Name at least 2 syntax problems with this code:

if (x = 4) {
System.out.println("bananas");
else (x % 4) {
System.out.println("oranges");
}

double equality operator, missing bracket to close if, x % 4 isn't a boolean condition

500

What is the sum after the loop runs?

int sum = 0;
for (int i = 0; i < 4; i++){
sum += i;
}

6
500

Name at least 2 problems with the following code that tries to declare an initialize a new 2D array of ints:

int[][] = q_array new String[4];

int vs String, 2D vs 1D, = in wrong place

500

What two things can the + operator do?

add two numbers, concatenate two Strings

500

Accessing array[5] in an array of length 5 results in ...

an out of bounds exception

M
e
n
u