Free Online Flashcard Deck

Java One-Dimensional Array Algorithms Free Online FlashCards

Study Java One-Dimensional Array Algorithms with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.

12 cards
01
Front

What is a one-dimensional array?

Back

A fixed-size object that stores multiple values of the same type, such as int, double, boolean, or String references.

02
Front

What indices are valid for an array of length n?

Back

For an array of length n, the valid indices are 0 through n - 1. Java arrays use zero-based indexing.

03
Front

What does int[] scores; do?

Back

Declaration creates a reference variable but not an array object. For example, int[] scores; declares scores without allocating its elements.

04
Front

What are Java array defaults after new?

Back

new int[5] creates five elements initialized to 0. Java also defaults double to 0.0, boolean to false, and reference types to null.

05
Front

What is the length of int[] values = {4, 8, 15, 16, 23}?

Back

The initializer list supplies five values, so values.length is 5. An initializer list creates the array and infers its length.

06
Front

How do you modify one array element?

Back

Use square brackets with an index, such as values[1] = 20, to modify one element. The assignment changes the array itself.

07
Front

When should you use an indexed for loop?

Back

Use an indexed for loop when the algorithm needs an element's position or must assign new values to the array.

08
Front

Why cannot a for-each variable modify an array?

Back

The loop variable receives a copy of each element, so assigning to it does not change the array. Use an indexed loop to modify array elements.

09
Front

What does indexOf({12, 7, 19, 7, 10}, 7) return?

Back

indexOf returns 1, the first index containing 7. It stops at the first match even though 7 appears again at index 3.

10
Front

What does countEven({12, 7, 19, 4, 10}) return?

Back

countEven returns 3 because 12, 4, and 10 are even. A counting algorithm starts at 0 and increments once per matching element.

11
Front

What is the average of {12, 7, 19, 4, 10}?

Back

The sum is 52 and the length is 5, so the average is 10.4. Use (double) total / values.length to avoid integer division.

12
Front

What is the maximum of {-8, -3, -12}?

Back

The maximum is -3. Initializing max with the first element works even when every array value is negative; starting max at 0 would be incorrect here.