AP CSA FRQ Guide
2022 FRQ 4: Data
Write two methods for a 2D integer grid. The first fills every grid cell with a random valid value that is divisible by 10 but not by 100. The second counts how many columns are in nondecreasing order from top to bottom.
Skills Tested
What this FRQ is really practicing
Treat these skills as the study checklist. If any tag feels shaky, review that topic before attempting the full written response.
Starter Approach
How to begin without copying a solution
- 1Part A: traverse every row and column of grid.
- 2Generate random values between 1 and MAX inclusive until the value is divisible by 10 and not divisible by 100.
- 3Assign a valid random value to every grid element.
- 4Part B: examine each column from top to bottom.
- 5Count a column when every value after the first is greater than or equal to the value above it.
Write a first attempt before revealing any solution outline. Most AP CSA FRQ progress comes from tracing your own code and finding the missing case.
Common Mistakes
Mistakes to watch for while writing
Self Check
Review questions before you submit
Defines repopulate with void return type and no parameters.
Part A modifies the grid directly.
Uses nested loops to visit every grid cell.
Loop over grid.length and grid[0].length.
Uses Math.random to generate candidate values.
Generate a random integer in the range 1 through MAX.
Generates values from 1 through MAX inclusive.
A common pattern is (int)(Math.random() * MAX) + 1.
Requires generated values to be divisible by 10.
Use modulo 10.
Rejects generated values divisible by 100.
Use modulo 100 and reject zero remainders.
Assigns a valid value into each grid cell.
Each grid[row][col] should receive the generated valid value.
Defines countIncreasingCols with int return type and no parameters.
Part B returns a count of columns.
Practice Links
