AP CSA 2022 Q4 - Data Class
| <-- Back to Solution of Q3 (ReviewAnalysis) - FRQ - 2022 | Home to AP CSA Exam Solutions--> |
Solution of Q4 (Data) - Free Response Question - 2022
The original question can be found at: https://apcentral.collegeboard.org/media/pdf/ap22-frq-computer-science-a.pdf
Part (a)- public void repopulate()
public void repopulate()
{
int rand=0;
grid = new int [3][3];
for (int i=0; i< grid.length; i++) {
for (int j=0; j < grid[0].length; j++)
{
rand= (int)(Math.random() * MAX );
while (!(rand%10 == 0) || (rand %100 ==0))
{
rand= (int) (Math.random() * MAX);
}
grid[i][j] = rand;
}
}
}
Part (b)- public int countIncreasingCols()
public int countIncreasingCols()
{
int count=0;
boolean order =false;
for (int col=0; col< grid[0].length; col++) {
order = true;
for (int row=1; row < grid.length; row++)
{
if (grid[row][col] < grid[row-1][col]) order =false;
}
if (order == true) count ++;
}
return count;
}
Java project files (with Runner code):
| <-- Back to Solution of Q3 (ReviewAnalysis) - FRQ - 2022 | Home to AP CSA Exam Solutions--> |