How a array of 3 work in java code. explain it ( shows the output and some part of the program , this is optional)
or example i will appreciated
do you need an arraylist or a set value container?
either way is fine
What do you want exactly? How you intialize an array? Or how to use it for an output? Or just a general introduction to arrays?
the output and the array code as i iknow is look like this a[][][]=[12][7][2] or a[][]=[12][9][2]
When you initialize an array it looks like this: int[] a = new int[10]; After this you've created the array with place for ten int-variables. If you want to make a multi-dimensional array it looks like this: int[][] b = new int[10][2]; This line creates a two-dimensional array, which provides place for ten one-dimensional arrays. So if you want to put something in b you have to write this: b[0][0] = 2; b[0][1] = 3; So far to the intializing. If you want to get the values from the array and to print them on the console you have to write this: System.out.println("x:"+b[0][0]+" y:"+b[0][1]) This will give you this output on the console: x:2 y:3 You can only access one element (or better: object) at a time. Is this, what you wanted to know?^^
what about he output when is that array
An array itself has no predefined output, you have some ways to do it, i described the easiest way in the second paragraph of the post above. You just have to make a printline and then the string, where you can fill in the values from the array.
ok
And in addition: An array like int[][] a = new int[10][3]; creates a table with 3 columns and 10 rows - its an array of arrays. With an array like this: int[][][] b = new int[10][3][3]; you would create a three-dimensional array - an array of an array of an array. This would not be a table anymore - more a cube (if you model arrays in a 3D room, thats way more comfortable than making notes about that). It would more be like a cube. Always think of that every square brackets create a new dimension of arrays.
thanks
Join our real-time social learning platform and learn together with your friends!