• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 2 out of 11 pages
Exam (elaborations)

Ap Computer Science Practice Exam A

Document preview thumbnail
Preview 2 out of 11 pages

AP COMPUTER SCIENCE PRACTICE EXAM A

Content preview

AP COMPUTER SCIENCE PRACTICE EXAM A

Consider the following method.

public static int mystery(int[] arr)
{
int x = 0
for (int k = 0; k < arr.length; k = k + 2)
x = x + arr[k]
return x;
}
Assume that the array nums has been declared and initialized as follows.
int[] nums = {3, 6, 1, 0, 1, 4, 2};

(A) 5
(B) 6
(C) 7
(D) 10
(E) 17 - Answer -(C) 7

Consider the following partial class declaration.

public class SomeClass
{
private int myA;
private int myB;
private int myC;
// Constructor(s) not shown
public int getA
{ return myA; }
public void setB(int value)
{ myB = value; }
The following declaration appears in another class.
SomeClass obj = new SomeClass();
Which of the following code segments will compile without error?
(A) int x = obj.getA();
(B) int x;
obj.getA(x);
(C) int x = obj.myA
(D) int x = SomeClass.getA();
(E) int x = getA(obj); - Answer -(A) int x = obj.getA

Which of the following changes to SomeClass will allow other classes to access but not
modify the value of myC ?
(A) Make myC public.

, (B) public int getC()
{ return myC; }

(C) private int getC()
{ return myC; }

(D) public void getC(int x)

(E) private void getC(int x)
{ x = myC; } - Answer -(B) public int getC()
{ return myC; }

Consider the following code segment.
int x = 7;
int y = 3;

if ((x < 10) && (y < 0))
System.out.printIn("Value is: " + x * y);
else
System.out.printIn("Value is: " + x / y);
What is printed as a result of executing the code segment

(A) Value is: 21
(B) Value is: 2.3333333
(C) Value is: 2
(D) Value is: 0
(E) Value is: 1 - Answer -(B) 2.3333333

Consider the following method.
public ArrayList<Integer> mystery(int n)
{
ArrayList<Integer> seq = new ArrayList<Integer>();
for (int k = 1; k <= n; k++)
seq.add(new Integer(k * k + 3));

return seq
}
Which of the folowing is printed as a result of executing the following statement?
System.out.printIn.(mystery(6));
(A) [3, 4, 7, 12, 19, 28]
(B) [3, 4, 7, 12, 19, 28, 39]
(C) [4, 7, 12, 19, 28, 39]
(D) [39, 28, 19, 12, 7, 4]
(E) [39, 28, 19, 12, 7, 4, 3] - Answer -(C) [4, 7, 12, 19, 28, 39]

Document information

Uploaded on
November 10, 2025
Number of pages
11
Written in
2025/2026
Type
Exam (elaborations)
Contains
Questions & answers
$14.99

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
GEEKA
3.8
(376)
Sold
2223
Followers
1450
Items
62835
Last sold
1 day ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions