I'm currently doing some online classes to learn Java. I feel like the book I'm reading has a ton of examples without enough explanations. Right now I'm trying to understand arrays and multidimensional arrays. Right now there's a discussions that came up in the class. It assumes the following:
How many elements are in the array?
What is x.length?
What is x[2].length?
What is x[0][0].length?
Now, I know there are 120 elements in the array because 12 5 2 = 120.
However, I'm not understanding why the .length gives me the following numbers: 12, 5, 2.
I feel like I could have guessed the answers and got it correctly. But guessing doesn't quite help me understand arrays. In order for me to get the answers, I just created a class in eclipse to print the length.
Can someone provide some more insight into multi-dimensional arrays?
PHP Code
<?php
int[][][] x = new int[12][5][2]
How many elements are in the array?
What is x.length?
What is x[2].length?
What is x[0][0].length?
Now, I know there are 120 elements in the array because 12 5 2 = 120.
However, I'm not understanding why the .length gives me the following numbers: 12, 5, 2.
I feel like I could have guessed the answers and got it correctly. But guessing doesn't quite help me understand arrays. In order for me to get the answers, I just created a class in eclipse to print the length.
Can someone provide some more insight into multi-dimensional arrays?
PHP Code
<?php
public class multidim {
public static void main(String[] args) {
int[][][] x = new int[12][5][2];
System.out.println(x.length);
System.out.println(x[2].length);
System.out.println(x[0][0].length);
}
}
![[Image: E0PaFmi.gif]](https://i.imgur.com/E0PaFmi.gif)
Quick Love for Quick Love



![[Image: 0DvFxnA.gif]](https://i.imgur.com/0DvFxnA.gif)