Virtual Rubik’s cubes. [Java 3D arrays]

Recently a friend of mine (Junior batch) was finding it difficult to understand an assignment that he was given based on 3D arrays in Java. So he asked me to have a look. After looking at the question I knew that it wasn’t going to be easy.  But I was able to eventually rig out a solution to tackle this tricky problem.

Basically, in order to understand 3D arrays in Java, one must know what 2D arrays are first. 2D arrays are arrays of arrays. 2D arrays could be visualized as a table with rows and columns. Therefore you would need 2 loops to access an element in a 2D array – One to iterate through the “rows” and the other to iterate through the “columns”.

If one could clearly understand 2D arrays then the only additional thing in 3D arrays that they need to know is that 3D arrays are arrays of 2D arrays. It could be visualized as a Rubik’s cube. (We need to check for a side in a Rubik’s cube other than the row and the column). In order to access (and/or manipulate) elements we need another loop (i.e. 3 loops in total).

The tricky part in 3D arrays are visualizing how they work, when it comes to developing solutions to problems. So this assignment was created to test student’s ability to tackle such situations.

Give me the link already!

Here is the link to the solution I came up with (The assignment question is also available as a PDF). https://github.com/ihsanizwer/TableMan. If you know how this could be optimized,or have any questions on this,  then please do let me know in the comments or by contacting me 🙂

Posted in Dev.