Solved PYQs 1-3 of 256: AP (Advanced Placement) Computer Science (A)

256 PYQs (12 FRQs) with Explanations (2026-2027 Exam)

Rs. 250.00

3 Year Validity

TopicsDetailsSample

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.

  1. public class name
  2. {
  3. private String fullname;
  4. private String firstName;
  5. private String middleName;
  6. private string lastName;
  7. public static final String BLANK = " " ;
  8. public Name ( String aFullName ) ;
  9. {
  10. fullName = aFullName;
  11. int index = fullName.indexOf ( BLANK ) ;
  12. String s = " " ;
  13. / * code to get firstName * /
  14. / * code to get lastName * /
  15. //The rest of the constructor is niot shown.
  16. }
  17. //Other instances variables and methods are not shown.
  18. }

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;

Unit 2: Using Objects (5% - % )

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);

Unit 2: Using Objects (5% - % )

Question 3
MCQ: Read the question, then carefully choose the correct answer(s).

Consider an array of integers arr, initially sorted.

Table Supporting: AP Computer Science A Mcq 3
012…495051
012…495051

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.)

  1. for ( int i = arr.length - 1; i > 0; i … )
  2. {
  3. int index = ( int ) ( Math.random ( ) * ( i + 1 ) ) ;
  4. swap ( arr [ i ] , arr [ index ] ) ;
  5. }

Which is the best description of what the algorithm does?

Unit 6: Array (10% -15% )

🏠ExamsAP (Advanced Placement)Computer Science (a) (Plan)Questions (Topics)