What is the smallest and largest possible value of Randomizer.nextInt(5, 12)?
5 and 12.
What keyword allows a program to choose between two different paths?
if
Which type of loop is best when you know exactly how many times you want something to repeat?
For Loop
What does the Boolean operator ! do to a Boolean value?
It reverses a Boolean value: true becomes false and false becomes true.
What does the MOD operator return?
The remainder after division.
How many different integer values can Randomizer.nextInt(20, 30) generate?
11 possible values.
What will print?
var score = 85;
if (score >= 90) {
println("Excellent");
} else {
println("Keep practicing");
}
Keep practicing
How many times will this loop print "Scan"?
for (var i = 0; i < 6; i++) {
println("Scan");
}
6 times
What does the expression true && false evaluate to?
false
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.
What will be printed?
var x = 8;
var y = 3;
var result = x + y * 2;
println(result);
14
What will print?
var attempts = 3;
if (attempts > 5) {
println("Account locked");
} else if (attempts > 2) {
println("Warning");
} else {
println("Access granted");
}
Warning
What is the final value of count?
var count = 0;
for (var i = 1; i <= 5; i++) {
count += i;
}
15
Rewrite this expression using De Morgan's Law:
!(isHacked || isInfected)
!isHacked && !isInfected
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.
What is the value of total after this code runs?
var total = 0;
var num = 4;
total = total + num;
total = total * 2;
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
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
Simplify this Boolean expression:
(isAdmin && hasPassword) || (isAdmin && hasMFA)
isAdmin && (hasPassword || hasMFA)
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.
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);
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.
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.
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
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