The property "length" in an array refers to the number of elements it contains.
Think of an array as a line of people waiting for a roller coaster. The length of the array is like the number of people in the line.
constructor: A constructor is a special method used to create and initialize objects.
index: An index is a position within an array or list that represents the location of an element.
iteration: Iteration refers to the process of repeating a set of instructions or operations multiple times.
What will the following code do? ```java int[] array = new int[5]; for (int i = 0; i < array.length; i++) { array[i] = i * 2; } ```
How can we rewrite the following for loop as an enhanced for loop? int[] array = {30, 2, 5, 6} for (int i = array.length-1; i >= 0; i--) { System.out.println(array[i]); }
Can we rewrite the following for loop as an enhanced for loop? boolean[] array = {true, false, false, true, false, true} for (int i = 0; i < array.length; i+=6) { System.out.println(array[i]); }
What does the following code do? public static int[] codeBlock(int[] array) { int firstItem = array[0] for (int i = 0; i < array.length - 1; i++) { array[i] = array[i+1]; } array[array.length - 1] = firstItem; return array; }
What is returned by the following code if the array [16, 3, 5, 4] is passed in? public static int codeBlock(int[] array) { int x = 0; for (int y: array) { x += y; } return (double) sum / (array.length); }
If we call the following method on the array [10, 9, 3, 12, 5], what is returned? public static int[] codeBlock(int[] array) { int[] newArray = new int[array.length]; for (int i = 0; i < array.length; i++) { newArray[i] = array[array.length - i - 1]; } return newArray; }
© 2024 Fiveable Inc. All rights reserved.
AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.