Solved PYQs 1-3 of 256: AP (Advanced Placement) Computer Science (A)
256 PYQs (12 FRQs) with Explanations (2026-2027 Exam)
Welcome back! Your subscription is active. Please access it from questions with explanations%
Help me ChooseAlready Subscribed?
Question 1 (1 of 2 Based on Passage)MCQ: Read the question, then carefully choose the correct answer(s).
Passage
Questions refer to the following information.
Consider the Name class below.
public class name{private String fullname;private String firstName;private String middleName;private string lastName;public static final String BLANK = " " ;public Name ( String aFullName ) ;{fullName = aFullName;int index = fullName.indexOf ( BLANK ) ;String s = " " ;/ * code to get firstName * // * code to get lastName * ///The rest of the constructor is niot shown.}//Other instances variables and methods are not shown.}
A full name in the Name class consists of a first name, followed by a single blank, one middle initial, a period, another blank, and a last name. Some examples of full names are: John Q. Smith, Camilla J. Hernandez, Jo-Ann P. Green, and Zach K. Teukolsky-Adams.
Which is correct code for⟋⚹ code to get firstName ⚹⟋?
I. firstName = fullName - middleInitial - lastName;
II. firstName = fullName. substring (0, index);
III. for (int i = 0; i < index; i ++ )
IV. s += fullName. substring (i, i + 1);
V. firstName = s;
Question 2 (2 of 2 Based on Passage) MCQ: Read the question, then carefully choose the correct answer(s).
Which is correct code for⟋⚹ code to get lastName ⚹⟋?
I. lastName = fullName. substring (index + 4);
II. lastName = fullName. substring (index + 4, fullName. length () );
III. lastName = fullName. substring (firstName. length () + 4);
Question 3MCQ: Read the question, then carefully choose the correct answer(s).
Consider an array of integers arr, initially sorted.
| 0 | 1 | 2 | … | 49 | 50 | 51 |
| 0 | 1 | 2 | … | 49 | 50 | 51 |
Consider the following algorithm, which changes the array arr. (You may assume the existence of a swap method that interchanges two elements in the array.)
for ( int i = arr.length - 1; i > 0; i … ){int index = ( int ) ( Math.random ( ) * ( i + 1 ) ) ;swap ( arr [ i ] , arr [ index ] ) ;}
Which is the best description of what the algorithm does?