CSA unit 6 test review

CSA unit 6 test review

Professional Development

80 Qs

quiz-placeholder

Similar activities

DS QUIZ 1

DS QUIZ 1

Professional Development

85 Qs

Java Basics

Java Basics

Professional Development

81 Qs

SAP MDG_90

SAP MDG_90

Professional Development

80 Qs

Test STEM English IT

Test STEM English IT

1st Grade - Professional Development

85 Qs

Level 1

Level 1

Professional Development

80 Qs

CSA unit 6 test review

CSA unit 6 test review

Assessment

Quiz

Computers

Professional Development

Medium

Created by

Jeff Cougger

Used 2+ times

FREE Resource

80 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Consider the following code segment.
int[] arr = {1, 2, 3, 4, 5};
Which of the following code segments would correctly set the first two elements of array arr to 10 so that the new value of array arr will be {10, 10, 3, 4, 5} ?

arr[0] = 10;
arr[1] = 10;

arr[1] = 10;
arr[2] = 10;

arr[0, 1] = 10;

arr[1, 2] = 10;

arr = 10, 10, 3, 4, 5;

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Consider the following method.
public int[] transform(int[] a)
{
a[0]++;
a[2]++;
return a;
}
The following code segment appears in a method in the same class as transform.
/ missing code /
arr = transform(arr);
After executing the code segment, the array arr should contain {1, 0, 1, 0}. Which of the following can be used to replace / missing code / so that the code segment works as intended?
int[] arr = {0, 0, 0, 0};
int[] arr = new int[0];
int[] arr = new int[4];

I only

II only

III only

I and II

I and III

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Consider the following method. Method allEven is intended to return true if all elements in array arr are even numbers; otherwise, it should return false.

public boolean allEven(int[] arr)

{

boolean isEven = /* expression */ ;

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

{

/* loop body */

}

return isEven;

}

Which of the following replacements for /* expression / and / loop body */ should be used so that method allEven will work as intended?

/* expression // loop body */

false -----

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

isEven = true;

/* expression // loop body */

false-----

if ((arr[k] % 2) != 0)

isEven = false;

else

isEven = true;

/* expression // loop body */

true-----

if ((arr[k] % 2) != 0)

isEven = false;

/* expression // loop body */

true-----

if ((arr[k] % 2) != 0)

isEven = false;

else

isEven = true;

/* expression // loop body */

true-----

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

isEven = false;

else

isEven = true;

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Consider the following instance variable and incomplete method. The method is intended to return a string from the array words that would be last alphabetically.

private String[] words;

public String findLastWord()

{

/* missing implementation */

}

Assume that words has been initialized with one or more strings containing only lowercase letters. Which of the following code segments can be used to replace /* missing implementation */ so that findLastWord will work as intended?

int maxIndex = 0;

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

{

if (words[k].compareTo(maxIndex) > 0)

{

maxIndex = k;

}

}

return words[maxIndex];

int maxIndex = 0;

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

{

if (words[k].compareTo(words[maxIndex]) > 0)

{

maxIndex = k;

}

}

return words[maxIndex];

int maxIndex = 0;

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

{

if (words[k].compareTo(words[maxIndex]) > 0)

{

maxIndex = k;

}

}

return maxIndex;

String maxWord = words[0];

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

{

if (words[k].compareTo(maxWord) > 0)

{

maxWord = k;

}

}

return maxWord;

String maxWord = words[0];

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

{

if (words[k].compareTo(maxWord) > 0)

{

maxWord = words[k];

}

}

return maxWord;

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

A BoundedintArray represents an indexed list of integers. In a BoundedIntArray the user can specify a size, in which case the indices range from 0 to size - 1. The user can also specify the lowest index, low, in which case the indices can range from low to low + size - 1.

public class BoundedIntArray

{

private int[] myItems; // storage for the list

private int myLowIndex; // lowest index

public BoundedIntArray(int size)

{

myItems = new int[size];

myLowIndex = 0;

}

public BoundedIntArray(int size, int low)

{

myItems = new int[size];

myLowIndex = low;

}

// other methods not shown

}

Consider the following statements.

BoundedIntArray arrl = new BoundedIntArray(100, 5);

BoundedIntArray arr2 = new BoundedIntArray(100);

Which of the following best describes arrl and arr2 after these statements?

arrl and arr2 both represent lists of integers indexed from 0 to 99.

arrl and arr2 both represent lists of integers indexed from 5 to 104.

arrl represents a list of integers indexed from 0 to 104, and arr2 represents a list of integers indexed from 0 to 99.

arrl represents a list of integers indexed from 5 to 99, and arr2 represents a list of integers indexed from 0 to 99.

arrl represents a list of integers indexed from 5 to 104, and arr2 represents a list of integers indexed from 0 to 99.

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Consider the following method, which is intended to return the number of strings of length greater than or equal to 3 in an array of String objects.
public static int checkString(String[] arr)
{
int count = 0;
for (int k = 0; k < arr.length; k++)
{
if (arr[k].length() >= 3)
{
count++;
}
}
return count;
}
Which of the following code segments compile without error?
checkString(new String[]);
checkString(new String[0]);
String[] str = {"cat", "dog"};checkString(str);

II only

III only

I and III only

II and III only

I, II, and III

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Consider the following instance variable and incomplete method. The method calcTotal is intended to return the sum of all values in vals.

private int[] vals;

public int calcTotal()

{

int total = 0;

/* missing code */

return total;

}

Which of the code segments shown below can be used to replace /* missing code */ so that calcTotal will work as intended?

I. for (int pos = 0; pos < vals.length; pos++)

{

total += vals[pos];

}

II. for (int pos = vals.length; pos > 0; pos--)

{

total += vals[pos];

}

III. int pos = 0;

while (pos < vals.length)

{

total += vals[pos];

pos++;

}

I only

II only

III only

I and III

II and III

Create a free account and access millions of resources

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?