Multi-dimensional Arrays

From CompSciWiki
Revision as of 11:46, 15 April 2010 by AndreyR (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Back to the Program-A-Day homepage

Problem

Create three arrays, two that are 2-dimensional (2-d) and a third one that is 3 dimensional (3-d). The first 2-d array will be 5x5 and you will need to store an integer value that will correspond to the row and column in the array, ie. 24, means row 2 column 4. The second 2-d array will store the multiplication table from 1 to 9. The 3-d array will store the sum co-ordinates on the cube created by visualizing the array where the centre of the cube is 0,0,0 so a 5x5x5 array would have the co-ordinates (0,0,0) at location 3 (location 2 in the java array since indexing starts at 0) ie. co-ordinate (1,-2,0) would be array[3][0][2] and would store the value 1+(-2)+0= -1. All co-ordinates in the 3-d array will be in the form (x,y,z) and correspond directly to the 3-d array in the same form, so the 3-d array would be indexed array[x][y][z]. Create a 7x7x5 3-d array. All arrays will be integer arrays and all arrays are to be created with corresponding methods that take parameters and return a newly created array.

 

Introducing Arrays

Wiki array01.jpg

Solution

Code

Solution Code

Back to the Program-A-Day homepage