Using two-dimensional arrays in Java
public class Array2D ... {
public static void Main (string[] args) ... {
int myint[][]=new int[5][10];
Traversal, assigning values to each array of arrays
for (int i=0;i<myint.length;i++) ... {
for (int j=0;j<myint[0].length;j++) ... {
Myint[i][j]=i*j;
}
}
System.out.println ("myint.length=" +myint.length+ ", myint[0].length=" +myint[0].length);
The lower and upper bounds of each dimension of the output array
for (int i=0;i<myint.length;i++) ... {
for (int j=0;j<myint[0].length;j++) ... {
System.out.println ("myint[" +i+ "] [" +j+ "]=" +myint[i][j]);
}
}
}
in C # int[][] MyInt is declaring a jagged array, declaring a two-dimensional array is so declared int[,] myInt, if the above code is replaced by C #, it needs to be represented as follows:
Class CLSARRAT2D
{
/**////<summary>
The main entry point for the application.
</summary>
[STAThread]
static void Main (string[] args)
{
int[,] myint=new int[5,10];
Traversal, assigning values to each array of arrays
for (int i=myint.getlowerbound (0); i<=myint.getupperbound (0); i++)
{
for (int j=myint.getlowerbound (1); J<=myint.getupperbound (1); j + +)
{
Myint[i,j]=i*j;
}
}
The lower and upper bounds of each dimension of the output array
for (int i=0;i<myint.rank;i++)
{
Console.WriteLine ("{0} {1} {2}", I, Myint.getlowerbound (i), Myint.getupperbound (i));
}
Traversal, outputting the number of each element in a two-dimensional array
for (int i=myint.getlowerbound (0); i<=myint.getupperbound (0); i++)
{
for (int j=myint.getlowerbound (1); J<=myint.getupperbound (1); j + +)
{
Console.WriteLine ("Myint[{0},{1}]={2}", I,j,myint[i,j]);
}
}
Console.ReadLine ();
}
}