Recall & Review
beginner
What is a one-dimensional array in Java?
A one-dimensional array in Java is a collection of elements of the same type stored in a single row. It allows you to store multiple values in a single variable, accessed by an index starting at 0.
touch_appClick to reveal answer
beginner
How do you declare a one-dimensional array of integers named 'numbers' with 5 elements in Java?
You declare it like this:
This creates an array that can hold 5 integers, all initially set to 0.
int[] numbers = new int[5];This creates an array that can hold 5 integers, all initially set to 0.
touch_appClick to reveal answer
beginner
How do you access the third element in a one-dimensional array named 'data'?
You access it using its index:
Remember, array indexes start at 0, so the third element is at index 2.
data[2]Remember, array indexes start at 0, so the third element is at index 2.
touch_appClick to reveal answer
intermediate
What happens if you try to access an array index that is out of bounds in Java?
Java throws an ArrayIndexOutOfBoundsException. This means you tried to access an index less than 0 or greater than or equal to the array length.
touch_appClick to reveal answer
beginner
How can you initialize a one-dimensional array with values at the time of declaration?
You can write:
This creates an array with 5 elements already set to those values.
int[] numbers = {10, 20, 30, 40, 50};This creates an array with 5 elements already set to those values.
touch_appClick to reveal answer
What is the index of the first element in a Java array?
Which of the following is the correct way to declare a one-dimensional array of doubles named 'prices' with 10 elements?
What will happen if you try to access array element at index 5 in an array declared as
int[] arr = new int[5];?How do you find the length of an array named 'items' in Java?
Which of these initializes an array with values 1, 2, 3 in one line?
Explain what a one-dimensional array is and how you declare one in Java.
Describe how to access and modify elements in a one-dimensional array in Java.
