Randomizer & Variables
Conditionals
Loops
Boolean Logic
Algorithms & Functions
100

What is the smallest and largest possible value of Randomizer.nextInt(5, 12)?

5 and 12.

100

What keyword allows a program to choose between two different paths?

if

100

Which type of loop is best when you know exactly how many times you want something to repeat?


For Loop

100

What does the Boolean operator ! do to a Boolean value?


It reverses a Boolean value: true becomes false and false becomes true.

100

What does the MOD operator return?


The remainder after division.

200

How many different integer values can Randomizer.nextInt(20, 30) generate?

11 possible values.

200

What will print?

var score = 85;

if (score >= 90) {
    println("Excellent");
} else {
    println("Keep practicing");
}

Keep practicing

200

How many times will this loop print "Scan"?

for (var i = 0; i < 6; i++) {
    println("Scan");
}

6 times

200

What does the expression true && false evaluate to?

false

200

In AP pseudocode, what is the difference between REPEAT 5 TIMES and REPEAT UNTIL(condition)?


REPEAT 5 TIMES runs a fixed number of times. REPEAT UNTIL(condition) repeats until the condition becomes true.

300

What will be printed?

var x = 8;
var y = 3;
var result = x + y * 2;
println(result);

14

300

What will print?

var attempts = 3;

if (attempts > 5) {
    println("Account locked");
} else if (attempts > 2) {
    println("Warning");
} else {
    println("Access granted");
}

Warning

300

What is the final value of count?

var count = 0;

for (var i = 1; i <= 5; i++) {
    count += i;
}

15 

300

Rewrite this expression using De Morgan's Law:

!(isHacked || isInfected)


!isHacked && !isInfected

300

 A robot starts at position (1,1), facing east. It moves forward 4 spaces, turns left, and moves forward 2 spaces. What is its final position and direction?


Position (5,3), facing north.

400

What is the value of total after this code runs?

var total = 0;
var num = 4;
total = total + num;
total = total * 2;


8
400

A security program should display "Access Granted" only when a password is correct AND the account is active. Write the Boolean condition using the variables passwordCorrect and accountActive.


passwordCorrect && accountActive

400

How many total times will "Check" print?

for (var i = 0; i < 3; i++) {
    for (var j = 0; j < 4; j++) {
        println("Check");
    }
}


12 times

400

Simplify this Boolean expression:

(isAdmin && hasPassword) || (isAdmin && hasMFA)

isAdmin && (hasPassword || hasMFA)

400

What is the purpose of a function's RETURN statement?

It sends a value back to the part of the program that called the function.

500

Write a line of code that generates a random integer from 1 through 100 and stores it in a variable named securityCode.

var securityCode = Randomizer.nextInt(1, 100);

500

Find the logic error. Why will this program always display "Access Denied"?

if (passwordCorrect) {
    println("Access Granted");
}
println("Access Denied");


The final println("Access Denied") is outside the if statement, so it always runs. Put it inside an else block.

500

What is wrong with this loop, and how could you fix it?

var attempts = 0;

while (attempts < 5) {
    println("Trying password...");
}


attempts never changes, so the condition stays true. Add attempts++; inside the loop.

500

A system should allow access only if the user has entered the correct password, completed MFA, and the account is not locked. Write the Boolean condition using:

  • passwordCorrect

  • mfaComplete

  • accountLocked


passwordCorrect && mfaComplete && !accountLocked

500

Write AP pseudocode that counts how many even numbers are between 1 and 10, inclusive. Store the answer in a variable named count.


count ← 0
number ← 1

REPEAT 10 TIMES
{
    IF (number MOD 2 = 0)
    {
        count ← count + 1
    }
    number ← number + 1
}

DISPLAY count

Answer: 5

M
e
n
u