AP Computer Science Unit 6 Test Project Stem

0.0(0)
studied byStudied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/19

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 11:22 AM on 2/27/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

20 Terms

1
New cards

public static int[] p()

{ / / ... }

public static void main(String[] args)

{

int[] arr = p();

/ / ...

}

What return statement may be used in p() ?

return new int[3];

2
New cards

public static int mystery(int a[], int x) {

int c = 0;

for ( int i = 0; i < a.length; i++) {

if (a[i] == x)

{ c++;

} }

return c; }

Returns a count of the number of times x appears in the array.

3
New cards

private int[] nums;

/ ** print the indices of all the elements in nums which are even numbers

*/ public void printEvenIndices()

{ / missing code / }

Which of the following replacements for / missing code / correctly implements the method printEvenIndices()

for (int k = 0; k < nums.length; k++)

{

if (nums[k] % 2 == 0)

{

System.out.println(k);

}

}

4
New cards

public static int mystery(String[] a, int x)

{

int c = 0;

for (int i = 0; i < a.length; i++)

{

if (a[i].length() > x)

{

c++;

}

}

return c;

}

What is output by the following code?

String[] b = {"aardvark", "banana", "cougar", "daikon", "elephant", "fog", "get"};

System.out.println(mystery(b, 5));

5

5
New cards

When you pass an array to a method, the method receives ______.

a copy of the reference to the array

6
New cards

public static void mystery(int[] nums)

{

for (int i = 0; i < nums.length; i++)

{

if (nums[i] % 2 != 0)

{

nums[i]++;

}

}

}

Changes all the values in the array to even numbers.

7
New cards

public static String mashup(String str, int[] arr)

{

String result = "";

for (int x : arr)

{

result = result + str.substring(0, x);

}

return result;

}

The following code appears in another method in the same class.

int[] nums = {1, 5, 3};

String word = "program";

System.out.println(mashup(word, nums));

pprogrpro

8
New cards

public static boolean mystery(int nums[])

{

for (int i = 1; i < nums.length; i++)

{

if (nums[i - 1] >= nums[i])

{

return false;

}

}

return true;

}

Returns true if each element of the array is greater than the element before.

9
New cards

int[] seq = {0, 1, 2, 5, 3, 7};

for (int k = 1; k < seq.length; k++)

{

seq[k] = seq[k-1];

}

Which of the following represents the contents of seq as a result of executing the code segment?

{0, 0, 0, 0, 0, 0}

10
New cards

Consider the following methods which appear within the same class.

public static void mystery(int[] data)

{

for (int k = 0; k < data.length - 1; k+=2)

{

int t = data[k];

data[k] = data[k+1];

data[k + 1] = t;

}

}

public static String toString(int[] data)

{

String str = "";

for (int d : data)

{

str = str + d + " ";

}

return str;

The following code segment appears in the main method of the same class.

int[] nums = {1, 2, 7, 3, 5};

mystery(nums);

System.out.println(toString(nums));

2 1 3 7 5

11
New cards

public static void doStuff (int a[], int b)

{

if (/ Missing Code /)

{

for (int i = b; i < a.length; i++)

{

a[i] = a[i] * 2;

}

}

}

b >= 0 && b < a.length

12
New cards

int a [] = {64 , 66 , 67 , 37 , 73 , 70 , 95 , 52 , 81 , 82};

for (int i = 0; i < a.length; i++)

{

a[i] = a[i] / 10;

}

for (int i =0; i < a.length; i++)

{

System.out.print(a[i] + " ");

}

What is output?

6 6 6 3 7 7 9 5 8 8

13
New cards

private int[] nums;

/** @param val any int value

*/

public int mystery(int val)

{

int k = 0;

while (k < nums.length && nums[k] < val)

{

k++;

}

return k;

}

Suppose that the call mystery(10) returns a value of 7. Which of the following MUST be true about nums?

The elements at indices from 0 to 6 inclusive in nums are all less than 10.

14
New cards

int[] seq = {3, 1, 8, 4, 2, 5};

for (int k = 1; k < seq.length; k++)

{

if (seq[k] >= seq[0])

{

System.out.print(seq[k] + " " + k + " ");

}

}

What is output?

8 2 4 3 5 5

15
New cards

public static mystery(int a[])

{

int m = a[0];

for (int i = 0; i < a.length; i++)

{

if (m > a[i])

{

m = a[i];

}

}

return m;

}

What would be returned by mystery if it was passed the following array?

int[] a = {34, 18, 34, 38, 27, 37, 39, 21, 19}

18

16
New cards

private int[] nums;

/** Precondition: nums.length > 0

* @param n an int value representing a valid index of nums

*/

public int numsInfo(int n)

{

int result = n;

for (int k = n - 1; k >= 0; k--)

{

if (nums[k] == nums[n])

{

result = k;

}

}

return result;

}

The index of the first element in the array which has the same value as the element at position n.

17
New cards

Consider the following instance variable and method.

private String[] words;

public void mystery(int n)

{

for (int k = n; k < words.length; k += n)

{

words[k] = words[k - 1].substring(0, n);

}

}

Assume that words has been initialized with the following values.

{"abcde", "fghij", "klmno", "pqrst", "uvwxy"}

Which of the following represents the contents of the array words as a result of the call mystery(2)?

{"abcde", "fghij", "fg", "pqrst", "pq"}

18
New cards

public static double average(int[] nums)

{

int sum = 0;

for (int i = 0; i < nums.length; i++)

{

sum += nums[i];

}

return (1.0 * sum) / nums.length;

} //average

public static int[] mystery(String[] a)

{

int[] temp = new int[a.length];

for (int i = 0; i < a.length; i++)

{

temp[i] = a[i].length();

}

return temp;

} //mystery

What is output by running the following?

String[] spelling = {"against", "forms", "belief", "government", "democratic",

"movement", "understanding", "single", "followed", "scenario"};

System.out.println( average( mystery(spelling)));

8.1

19
New cards

Consider the following method which is intended to create an array which stores the decimal digits of the

positive int num in order of their place value (e.g. units first, then tens etc.).

/** @param num a positive integer

* @return an array containing each digit of num, with the units digit at index 0 and

* higher place value digits at higher indices.

*/

public int[] digits(int num)

{

int length = 0;

int pv = 1;

while (num >= pv)

{

length += 1;

pv *= 10;

}

int[] dig = new int[length];

for (int k = 0; k < length; k++)

{

/ missing code /

}

return dig;

}

Which of the following could replace / missing code / so the method digits works as intended?

dig[k] = num % 10;

num /= 10;

20
New cards

public static int mystery(int[] data)

{

int times = 0;

int counter = 0;

for (int j = 0; j < data.length; j++)

{

counter = 0;

for (int k = j; k < data.length; k++)

{

if (data[j] == data[k])

{

counter ++;

}

}

if (counter > times)

{

times = counter;

}

}

return times;

}

Assume that data has been declared and initialized as an array of integer values. Which of the following best

describes the value returned by the call mystery(data)?

The number of times that a most frequently occurring value appears in data.

Explore top notes

note
social studies chapter 7!
Updated 881d ago
0.0(0)
note
Historiography for WW1
Updated 1052d ago
0.0(0)
note
Elements and the Periodic Table!
Updated 1385d ago
0.0(0)
note
Chapter Twelve: Law
Updated 1108d ago
0.0(0)
note
Puella endings
Updated 371d ago
0.0(0)
note
social studies chapter 7!
Updated 881d ago
0.0(0)
note
Historiography for WW1
Updated 1052d ago
0.0(0)
note
Elements and the Periodic Table!
Updated 1385d ago
0.0(0)
note
Chapter Twelve: Law
Updated 1108d ago
0.0(0)
note
Puella endings
Updated 371d ago
0.0(0)

Explore top flashcards

flashcards
Toki Pona en Sitelen Pona
123
Updated 375d ago
0.0(0)
flashcards
Top 200 Drugs
600
Updated 901d ago
0.0(0)
flashcards
Short Story Diction
48
Updated 983d ago
0.0(0)
flashcards
Understanding Phlebotomy
228
Updated 1125d ago
0.0(0)
flashcards
Ruotsi
470
Updated 727d ago
0.0(0)
flashcards
Graden (copy)
66
Updated 1025d ago
0.0(0)
flashcards
Chinese 3 Semester 1 Final
234
Updated 435d ago
0.0(0)
flashcards
Toki Pona en Sitelen Pona
123
Updated 375d ago
0.0(0)
flashcards
Top 200 Drugs
600
Updated 901d ago
0.0(0)
flashcards
Short Story Diction
48
Updated 983d ago
0.0(0)
flashcards
Understanding Phlebotomy
228
Updated 1125d ago
0.0(0)
flashcards
Ruotsi
470
Updated 727d ago
0.0(0)
flashcards
Graden (copy)
66
Updated 1025d ago
0.0(0)
flashcards
Chinese 3 Semester 1 Final
234
Updated 435d ago
0.0(0)