Using a two-dimensional array in Java
Public class array2d ...{
Public static void main (string [] ARGs )...{
Int Myint [] [] = new int [5] [10];
// Traverse and assign values to each array
For (INT I = 0; I
For (Int J = 0; j
Myint [I] [J] = I * J;
}
}
System. Out. println ("Myint. Length =" + Myint. Length + ", Myint [0]. Length =" + Myint [0]. Length );
// Lower limit and upper limit of each dimension of the output Array
For (INT I = 0; I
For (Int J = 0; j
System. Out. println ("Myint [" + I + "] [" + J + "] =" + Myint [I] [J]);
}
}
}
}
In C #, int [] [] Myint declares an interleaved array, and declares that the two-dimensional array declares int [,] Myint. If the above Code is changed to C, it must be represented as follows:
Class clsarrat2d
{
/**////
/// Main entry point of the application.
///
[Stathread]
Static void main (string [] ARGs)
{
Int [,] Myint = new int [5, 10];
// Traverse and assign values to each array
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;
}
}
// Lower limit and upper limit of each dimension of the output Array
For (INT I = 0; I
{
Console. writeline ("{0} {1} {2}", I, Myint. getlowerbound (I), Myint. getupperbound (I ));
}
// Traverse to output 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 ();
}
}
Add to Vivi
Previous Article: Java Abstract class and interface humanized understanding
Next article: differences between the two exceptions in Java