Jump to content

Check out our Community Blogs

- - - - -

Multidimensional Array

Posted by kmilton7, 02 July 2012 · 2221 views

array novice multidimensional
An array allows us to store a set of values of a similiar data type. A multidimensional array allows us to store a set of sets of a particular data type (although you can have an array of one type containing an array of some other type, i think, hey it's a beginner's blog :-P ).

Ok, so here is an example of a 2 dimensional array containing day of the week and the presence of rain on that day. Here is the code:

String myWeek [] [];
myWeek [0] [0] = "Monday";
myWeek [0] [1] = "Rain";
myWeek [6] [0] = "Sunday";
myWeek [6] [1] = "No rain";
System.out.print ("Day\tPrecipitation");
for (int i=0; i < 7; i++){
	  for (int j=0; j < 2; i++){
		   System.out.println (myWeek [i] [j] + "\t");

The output is:
Day Precipitation
Monday Rain
Tuesday No Rain
Sunday No Rain

  • 0

One problem with this is you are not allocating memory for the string array so this code won't compile.
    • 0

Recent Entries

Recent Comments

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download