Array Practice

Array Practice#

These questions are to assess your understanding of arrays.

Question 1

True or False: If you create an array of length 5, you can change your mind later and add a sixth element.


Question 2

True or False: The code below will execute without error:

String[] stuff = {"hello", "pickle juice", "nineteen", "balloon"};
stuff[2] = 19;

Question 3

True or False: The code below will execute without error:

String[] otherStuff = {"19.8", "puzzles", "b3st fr13nD"};

Question 4

True or False: The code below will execute without error:

int[] nums = {4, -88, 1095, 7.2, 365};

Question 5

True or False: The code below will execute without error:

double[] otherNums = {-8.77, 4.96, 100, 98.6};

Question 6

True or False: The code below will execute without error:

boolean[] tests = new boolean[3];
tests[0] = true;

Question 7

True or False: The code below will execute without error:

String[] words = new String[5];
words[5] = "corgi";

Question 8

Write the output that would be produced by the following code:

String[] colors = {"red", "orange", "yellow", "green", "blue", "purple"};
for (int i = 0; i < colors.length; i++) {
    String nextColor = colors[i];
    System.out.print(nextColor.length() + " ");
}