Array Creation and Access
Traversing Arrays with For Loops
Enhanced for Loops for Arrays
Array Algorithms
Funny Fun Fun
100

Which of the following creates an array of 10 doubles called prices?

What is "double[] prices = new double[10];" 

100

Given the following code segment (which is identical to the method above) what will be returned when you execute: getIndexOfLastElementSmallerThanTarget(values,-13);

private int[ ] values = {-20, -15, 2, 8, 16, 33};

public static int getIndexOfLastElementSmallerThanTarget(int[ ] values, int compare)
{   for (int i = values.length - 1; i >=0; i--)   {      if (values[i] < compare)         return i;   }   return -1; // to show none found

1

100

What are some of the reasons you would use an enhanced for-each loop instead of a for loop?

I: If you wish to access every element of an array.
II: If you wish to modify elements of the array.
III: If you wish to refer to elements through a variable name instead of an array index.

I and III only.

100

How do we check if the space at the current index isn’t null?

if (spaces[index] != null)

100

Max level jump spell at town hall 12

level 3

200

Which index is for the last element of an array called highScores?


What is highScores.length - 1

200

Given the following code segment (which is identical to the method above) what will be returned when you execute: getIndexOfLastElementSmallerThanTarget(values, 7);

int[ ] values = {-20, -15, 2, 8, 16, 33};

public static int getIndexOfLastElementSmallerThanTarget(int[] values, int compare)
{   for (int i = values.length; i >=0; i--)   {      if (values[i] < compare)         return i;   }   return -1; // to show none found
}

out of bounds error

200

What is the output of the following code segment?

int[ ] numbers = {44, 33, 22, 11};
for (int num : numbers)
{    num *= 2;
}
for (int num : numbers)
{    System.out.print(num + " ");
}

44 33 22 11

200

Which loop should you use to solve this problem?

while

200

Who was the MLB national league MVP in 1913

Jake Daubert

300

Consider the following method. Given an array initialized to {4, 10, 15}, which of the following represents the contents of the array after a call to mystery(array, 2)?

public void mystery(int[] a, int i)
{   a[i] = a[i-1] * 2;
}

What is [4, 10, 20] 

300

Given the following values of a and the method doubleLast what will the values of a be after you execute: doubleLast()?

private int[ ] a = {-20, -15, 2, 8, 16, 33};

public void doubleLast()
{
   for (int i = a.length / 2; i < a.length; i++)   {      a[i] = a[i] * 2;   }
}

{-20, -15, 2, 16, 32, 66}

300

Given that array is an array of integers and target is an integer value, which of the following best describes the conditions under which the following code segment will return true?

boolean temp = false;
for (int val : array)
{  temp = ( target == val );
}
return temp;

Whenever the last element in array is equal to target. 

300

Which of the following correctly declares and creates the array to return?

int[] retArray = new int[num];

300

Translate:

كيف تبدو حالة الطقس اليوم؟

How does the weather look today?

400

Which of the following code segments, appearing in the same class as the mystery method, will result in array2 having the contents {5, 10, 20}?

public int[] mystery(int[] a, int i, int value)
{   a[i + 1] = a[i] + value;   return a;
}

int[] array1 = {5, 10, 15};
int[] array2 = mystery(array1, 1, 10);


400

Given the following values of a and the method mystery what will the values of a be after you execute: mystery()?

private int[ ] a = {-20, -15, 2, 8, 16, 33};

public void mystery()
{
   for (int i = 0; i < a.length/2; i+=2)   {      a[i] = a[i] * 2;   }
}

{-40, -15, 4, 8, 16, 33}

400

Which of the following correctly retrieves the name of a “Horse” object from the “spaces” array?

spaces[index].getName();

400

Which loop would be best for this problem?

for

400

How much head shot damage does a legendary bolt action sniper do in fortnite?

290

500

Given the following code segment, which of the following will cause an infinite loop? Assume that temp is an int variable initialized to be greater than zero and that a is an array of integers.

for ( int k = 0; k < a.length; k++ )
{   while ( a[ k ] < temp )   {      a[ k ] *= 2;   }
}

 Whenever a includes a value that is less than or equal to zero.

500

Which of the following loop headers will cause an ArrayIndexOutOfBounds error while traversing the array scores?

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

for (int i = scores.length - 1; i >= 0; i++)

500

What is the best way to compare two strings for equality?

str.equals(anotherString);

500

Which is the correct code for changing the current value to the negative of the limit?

samples[i] = -limit;

500

The third planet from the sun

What is earth