Exam 9: Advanced Array Concepts
You can add an item at any point in a(n) ____ container and the array size expands automatically to accommodate the new item.
A
int[][] myVals = new int[3][]
myVals[0] = new int[3];
myVals[1] = new int[10];
myVals[2] = new int[5];
The above code depicts a jagged array. What does this mean? Describe the rows and columns that make up this array.
In a two-dimensional array, each row also is an array. In Java, you can declare each row to have a different length. When a two-dimensional array has rows of different lengths, it is a jagged array because you can picture the ends of each row as uneven. You create a jagged array by defining the number of rows for a two-dimensional array, but not defining the number of columns in the rows.
The array is defined as follows:
int[][] myVals = new int[3][]
This statement declares an array with three rows, but the rows are not yet created. Then, the individual rows are declared using the following statements:
myVals[0] = new int[3];
myVals[1] = new int[10];
myVals[2] = new int[5];
myVals[0] has 3 elements/columns.
myVals[1] has 10 elements/columns.
myVals[2] has 5 elements/columns.
An array that you can picture as a column of values, and whose elements you can access using one subscript, is a ____ array.
A
What are some of the advantages of the ArrayList class over the Arrays class?
The Arrays class ____ method sorts the specified array into ascending order.
import javax.swing.*;
class FindPoints
{
public static void main(String[] args)
{
int[][] points =
{{10, 20, 30},
{20, 40, 60},
{40, 60, 80}};
String prompt;
int class;
int level;
prompt = JOptionPane.showInputDialog(null, "Class: ");
class = Integer.parseInt(prompt);
prompt = JOptionPane.showInputDialog(null, "Level: ");
level = Integer.parseInt(prompt);
JOption.showMessageDialog(null, "Your points: " + points[class][level]);
}
}
The above code depicts a two-dimensional array named points that refers to a Class and Level to determine a point value. If a user inputs a Class of 1 and a Level of 2, what point value will be displayed when the program executes? Explain how you arrived at your answer.
When you place objects in order beginning with the object that has the lowest value, you are sorting in ____ order.
With a two-dimensional array, the ____ field holds the number of rows in the array.
How can you use the length field with a two-dimensional array? Show an example two-dimensional array declaration and provide the length values for the example array.
How can you pass a two-dimensional array to a method? Provide some examples.
When using an insertion sort, each list element is examined one at a time and moved down if the tested element should be inserted before them.
To declare a two-dimensional array in Java, you type two sets of ____ after the array type.
Write the statement that assigns the integer value 20 to the first column of the first row of an array named myVals .
What import statements must be used before you can use an ArrayList class?
If you do not provide values for the elements in a two-dimensional numeric array, the values default to null .
The Arrays class ____ method puts a particular value in each element of the array.
int[][] myVals = {{2, 4, 6}, {1, 8, 9},
{1, 3, 5, 7}};
Using the above array, what is the value of myVals[1].length ?
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)