0
multidimensional areays
i dont really understand the concept and i really passed the quiz randomly, are them important, can someone explain better em?
9 Respuestas
+ 2
Single dimension arrays are used to store a objects of same type. For eg: To store employees record or students record.
Assume the case if you want to store students/employees informations from various departments. So multidimensional array comes in the picture.
For eg: Info _info [10][20];
Here first dimension (10) represents the number of department and second dimension (20) represents number of students in that particular department.
_info [0] pointing to the first department students information.
_info [2][3] pointing to the third department and 4 student information.
Hope this helps you to understand and usage for multidimensional Array.
+ 2
Sorry I am not sure what exactly your question is.
But, if you want to intialize the 2d array, you can achieve like this
info[][] = {{dept1stu1, dept1stu2,....},
{dept2stu1, dept2stu2,...},
{.....},
{.....},
.......
};
info[1][0] is pointing to dept2stu2. Hope it's helpful and addressed your doubt
+ 1
There are better methods for storing that information. For instance, using the Map collection, you can define a set of "keys" corresponding to the departments, and for each key, define an array representing students.
Map<String, String[]> deptRoll = new HashMap<String, String[]>();
deptRoll.put("dept1", {"stud1", "stud2", ...});
deptRoll.put("dept2", {"stud3", "stud4", ...});
System.out.println(deptRoll.get("dept1")[0]);
Output: "stud1"
+ 1
For two-dimensional arrays you can picture a matrix:
String [][] students = {
{"stud1", "stud2", "stud3"},
{"stud4", "stud5", "stud6"},
{"stud7", "stud8", "stud9"}
}
Array indices start with 0, so to reference an element at a given row-col position, you use arrayName[row - 1][col - 1].
For "stud6" in row 2, col 3, we write:
students[2 - 1][3 - 1]
which is
students[1][2]
which will return "stud6"
Higher-order arrays are also possible but harder to visualize, and often they are replaced by other structures better suited to multidimensional data.
+ 1
wow really thanks i was thinking about matrix but didnt realize how to do it, thanks!
+ 1
As Yellephant said there is hell lot of ways to store these dept student informations. But this question is related to multidimensional array I shown this example use array.
+ 1
int a[3][2][4][5];
the [3][2] is a 3x2 table.
the [4] makes them 4 tables, each is 3x2.
the [5] makes it 5 sets .. each set has 4 tables, each table is 3x2.
0
Thanks! but when u define a multidimensional array in code its like info[][] ={dep1, dep2} {student 1... or how u could express the students in each departament?
0
its good but i dont understand how the syntax exactly work