How to write program in array with 3 dimensional | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to write program in array with 3 dimensional

13th Dec 2017, 3:40 AM
buthina al Harthi
buthina al Harthi - avatar
2 Answers
+ 2
typehere[][][] arrayname = new typehere[inthere][inthere][inthere]; Replace 'typehere' with the type of your choice (int, char, Object, etc.), 'arrayname' with the name of your 3D array, and 'inthere' with the amount of array elements in each array. You could also initialize it with something like: {{{1}, {2}}, {{2}, {3}}, {{4}, {5}}}; instead of: new int[3][2][1];
13th Dec 2017, 3:52 AM
LunarCoffee
LunarCoffee - avatar
+ 2
First, you would need a reason to have the 3 dimension array. With a valid reason, the program becomes easier to understand and write. A valid reason would be making a spreadsheet program. The columns and rows displayed on the page would be 2 of the dimensions and the page tabs at the bottom of the page would be the third. With this image in mind, coding becomes a lot easier.
13th Dec 2017, 4:10 AM
John Wells
John Wells - avatar