Limited access

Upgrade to access all content for this subject

A jagged array is a special type of multidimensional array in which the member arrays have different lengths. This type of array is referred to as "jagged" because the irregular lengths produce a jagged appearance when the array is visualized.

The following array, animals, is an example of a jagged array:

String[][] animals = {{"Big", "Little"},
                      {"Red", "Orange", "Yellow", "Green", "Blue", "Indigo", "Violet"},
                      {"Ape", "Bat", "Cheetah", "Dog", "Elephant"}};

You are also provided with the following method, randomAnimal, which returns a single String using random elements from the three arrays contained in the animals jagged array:

String randomAnimal(String[][] animals) {
    int size = (int)(Math.random() * animals[0].length);
    int color = (int)(Math.random() * animals[1].length);
    int type = (int)(Math.random() * animals[2].length);

    return animals[0][size] + " " + animals[1][color] + " " + animals[2][type];

You make several calls to the randomAnimal method with the animals array as input. Answer the following questions about the Strings returned by these calls.

Select an assignment template