initialization of 3D array in java
-
int a[][] = { {1,2}, {2,3}}; this is how we can initialize an 2d array at the time of its deceleration but i don't know how to initialize an 3d array in java at the time of its deceleration. Please help me friends.. :doh:
an N-dimensional array is like a one-dimensional array where each element is an N-1 dimensional array. It gets initialized by providing initialization for all its elements, comma-separated and within curly brackets. You figured it out for 2D, now do the same for 3D. :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
int a[][] = { {1,2}, {2,3}}; this is how we can initialize an 2d array at the time of its deceleration but i don't know how to initialize an 3d array in java at the time of its deceleration. Please help me friends.. :doh:
int a[][][] = { { {1,1}, {1,2} }, { {2,1}, {2,2} } }; ...Perhaps a simple rule is the number of dimensions is equal to the number of opening curly braces at the start. Another point, are you sure you want a 3D array? what data are you storing?
I may or may not be responsible for my own actions