3 Multidimensional Arrays Flashcards
What is the syntax to create a multidimensional array? List 4 ways
int[][] vars1; // 2D array
int vars2 [][]; // 2D array
int[] vars3[]; // 2D array
String [][] rectangle = new String[3][2];
What does this make? int[] vars4 [], space [][];
int[] vars4 [], space [][]; // a 2D AND a 3D array
Write a loop that initializes a two D array.
x
Do the elements on next levels of a multidimensional array have to be the same size? Give an example.
No. They can be different sizes.
int[][] differentSize = {{1, 4}, {3}, {9,8,7}};
T or F, only the size of the first level of a multidimensional array has to be declared.
True. int [][] args = new int[4][]; is fine.
Write a loop to initialize every element of a twoD array and then for a 3D array.
Write them with a for loop and with an enhanced for loop.
x