Share on Google+Share on Google+

Multidimensional Array Java

Advertisement
Array is a collection of a same data type. When we have the data of the same type and same scope then its better to store it in an array. We use mostly two types of arrays that is simple array and multi dimensional array.

Multidimensional Array Java

        

Array is a collection of a same data type. When we have the data of the same type and same scope then its better to store it in an array. We use mostly two types of arrays that is simple array and multi dimensional array.  

In the example given below we have used two dimensional array. A two dimensional array can be thought as a grid of rows and columns. The first array will reflect to a row and the second one is column. In the example we have written it as int TwoArray[ ][ ]  = new int [7 ][12 ];.  In this example we will have 7 rows and 12 columns 

The output of the program is given below:

<HTML>
  <HEAD>
    <TITLE>Multidimensional Arrays in Jsp</TITLE>
  </HEAD>
    <BODY>
    <FONT SIZE="6" COLOR="#990000">Multidimensional Arrays in Jsp</FONT>
    <%
        int TwoArray[][] = new int[7][12];
		int a,b, c = 0;
		for(a=0; a < 4;a++){
						for(b=0; b<5;b++){
				TwoArray[a][b] =c;
				c++;
			}
				}
			for(a=0;a<4;a++){
				for(b=0;b<5;b++){
					out.println(TwoArray[a][b] + " ");
				}
				out.println("<br>");
			}
     %>
  </BODY>
</HTML>

Output of the Program:

Download this example.

Advertisements

Posted on: March 12, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: Multidimensional Array Java   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0