AP CSA

Control constructs To facts …

Topic Basic Intermediate Advanced
Conditional statements
Write single if statements involving simple boolean expressions in the condition.
Write consecutive if statements with mutually exclusive conditions.
Write if/else statements to choose between two blocks of code.
Translate consecutive if statements with mutually exclusive conditions into if/else statements when appropriate.
Write nested if statements, with and without else clauses.
Properly format nested if and if/else statements.
Write if/else if/else chains to choose between multiple blocks of code.
Translate consecutive if statements with mutually exclusive conditions into if/else if/else chains with simpler conditions when appropriate.
Combine consecutive if statements that do the same thing by combining their conditions.
Unnest nested if statements by combining their conditions.
Use the ternary operator ?: as an alternative to if/else when appropriate.
While loops
Write a while loop to print all the characters of a string up to a given character.
Convert a given for loop to an equivalent while loop plus initialization code.
Write the number guessing game.
Write code that uses a while loop to simulate a series of bets on fair coin flips where you double your money if you win and halve your money if you lose where betting stops once your money goes below a dollar or above a trillion dollars.
For loops
Identify the three clauses in a for loop: initializer, test, and updater.
Write a for loop to print each element of an array.
Write a for loop to print each character of a string.
Convert a given while loop plus initialization code to an equivalent for loop.
Use a for loop to test whether a given string is a palindrome.
Traverse rectangular 2d arrays using nested loops.
Traverse non-rectangular 2d arrays using nested loops.
Write code that uses nested for loops to print a rectangle of *s.
Write code that uses nested loops to print out a multiplication table.
Write code that uses nested loops to print out. a Vignère square or [tabula recta], given a String containing the alphabet.
Use break and continue statements to modify the flow of control in a loop.
Loop algorithms
Write a loop to count characters in a string that meet some criteria.
Write a loop to produce a reversed version of a string.
Write a loop to produce a new string containing only those characters of a given string that meet some criteria.
Write a loop to find the maximum character in a string according to compareTo.
Write a loop that prints the individual digits of an int from least significant to most significant. (Do not turn the whole int into a string!)
Use a loop to implement a method that does the same thing as String.indexOf given two String arguments.
Write a loop that produces a scrambled version of a string based on a given scrambling algorithm, e.g. swap every “A” with the following character unless it is also an “A”.
Write a loop to print the Fibonacci numbers up to a given limit.
Write a method that uses a loop to determine whether a given int value is prime.
Write code to print all the substrings of a string.
Array traversal
Loop over an array using a regular for loop from 0 to the array’s length.
Loop over a subsection of an array.
Loop over an array in reverse.
Loop over a subsection of an array in reverse.
Use the enhanced for loop where appropriate with arrays.
Translate between regular and enhanced for loops.
Array algorithms
Count elements of an array matching some criteria
Total elements of an array.
Compute the average of an array of numbers.
Find the first element of an array that matches some criteria.
Select a random element from an array.
Find the minimum or maximum value in an array.
Find the first element in a subsection of an array that matches some criteria.
Find the last element in a subsection of an array that matches some criteria.
Build a new array containing values computed from the elements of another array.
Rotate elements of an array forwards or backwards by one position, wrapping around the end of the array.
Write loops that compute using pairs of elements from an array: all pairs or all pairs ignoring order.
Write code to reverse the elements of an array in place.
Write code to examine or modify neighbors of an array element in a 2D array.