Professional Documents
Culture Documents
Unit 8 AP Computer Science Practice Exam
Unit 8 AP Computer Science Practice Exam
Two-Dimensional Arrays
1) Which of the following are true 4) Which of the following is the correct
about two-dimensional arrays? declaration of a String two-
dimensional array field meant to
I. All of the elements inside of an store sensitive data?
array must be of the same type or
related types. (A) String[][] data;
II. When creating an array with the (B) private String[][]
keyword new, integers are data;
initialized to 0. (C) public String[][]
III. The first row of an array is data;
located at the index of 1. (D) static String[][]
data;
(A) I only
(B) II only 5) Which of the following is the correct
(C) I and II initialization of a two-dimensional
(D) II and III array that should have 3 rows and 4
(E) I, II, and III columns?
I.
END OF SECTION I
This practice test was created by Ajay Gandecha.
This test and I are not affiliated with, or endorsed by, the College Board.
No questions are copied from the College Board and were made on my own for you to prepare.
Good luck!
Section II – Free Response Section
Optional Time – 15 minutes
1 Question
/** Returns true if a location on the battlefield has a land mine, returns false
* otherwise.
*/
public boolean hasMine(int row, int col)
{ /* to be implemented in part (a) */ }
/** Returns true if a soldier can walk across the battlefield at a given row
* without hitting a land mine, returns false otherwise.
*/
public boolean canSafelyCross(int rowToCross)
{ /* to be implemented in part (b) */ }
X 0 1 2 3 4
/** Returns true if a location on the battlefield has a land mine, returns false
* otherwise.
*/
public boolean hasMine(int row, int col)
NOTE THAT THE BATTLEFIELD GRID ALREADY HAS THE BOOLEAN VALUES
NOTE: You must use the hasMine method appropriately to receive full credit.
For example:
X 0 1 2 3 4
In the example, row 2 is the only one that would return true, as it is the only row
without any land mines.
/** Returns true if a soldier can walk across the battlefield at a given row
* without hitting a land mine, returns false otherwise.
*/
public boolean canSafelyCross(int rowToCross)
}
}
END OF SECTION II
This practice test was created by Ajay Gandecha.
This test and I are not affiliated with, or endorsed by, the College Board.
No questions are copied from the College Board and were made on my own for you to prepare.
Good luck!