Determine the Upper Bound of a Two-Dimensional Array in Java
Multi-Dimensional Array
Multi-faceted exhibits in Java are regular and can be named various clusters. Information in a two-layered bunch in Java is put away in 2D even structure. A two-layered collection is the most accessible type of complex exhibit. A two-layered cluster should be visible as a variety of the one-layered display for more straightforward comprehension. A two-layered exhibition is proclaimed with two aspects likewise alluded to as their limits.
Syntax for 2-Dimensional Array
data type[][] array name = new data type[x][y];
Example:
int [][] ar = new int [5][10];
How to Assign Values to a Multi-dimensional Array:
Syntax:
data_type[][] array_name = {{valueR1C1, valueR1C2, ....},
{valueR2C1, valueR2C2, ....}
};
Example:
//simple program for 2-d arrays
// Allocation of values in a 2-dimensional array
class MDA { //creating the class with the name MDA
public static void main(String[] args)
{
int[][] arr = new int[5][10]; //creating the 2-D array with 5 rows and 10 columns
arr[0][0] = 5; //assigning the value 5 to the 2-D array at the 0th row and 0th //column value
System.out.println(“printing the 2-D array elements”);
System.out.println("arr[0][0] = " + arr[0][0]);
}
}
Output:
Printing the 2-D array elements
arr[0][0] = 5
Example 1:
//simple program for 2-d arrays
// Allocation of values in a 2-dimensional array
class MDA{ //creating the class with the name MDA
public static void main(String[] args)
{
int[][] arr = { { 10, 20 }, { 30, 40 } }; //creating the 2-D array with 2 rows and 2 //columns
System. out.println(“Printing the 2-D array elements”);
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++) //printing the 2-D array elements
System.out.println("arr[" + i + "][" + j+ "] = " + arr[i][j]);
}
}
Output:
Printing the 2-D array elements
arr[0][0] = 10
arr[0][1] = 20
arr[1][0] = 30
arr[1][1] = 40
How to Determine the Upper Bound of a Two-Dimensional Array
A variety of Exhibits in java is a variety of a one-layered clusters. Each line of a two-layered exhibit has a length field that holds the number of sections.
Syntax
int row bound = arr name.length; //arr means array
int column bound = arr name[0].length;
Example:
//simple program to determine the Dimension of an Array
class MDA { //creating a class with the name MDA
public static void main(String args[])
{
int[][] arr = new int[8][15]; //creating the 2-D array of integer type with 8 //rows and 15 columns
int row_bound = arr.length; //declaring a integer variable and assigning the //length of the array
int column_bound = arr[0].length; //declaring an integer variable and //assigning the length of the 0th index array
System.out.println(“printing the dimensions of the given array”);
System. out.println("Dimension 1: " + row_bound); //prints the dimension of the //rows
System. out.println("Dimension 2: " + column_bound); //prints the dimension //of the columns
}
}
Output:
Printing the dimensions of the given array
Dimension 1: 8
Dimension 2: 15
Example 1:
//simple program to determine the Dimension of an Array
class MDA { //creating a class with the name MDA
public static void main(String args[])
{
int[][] ar = { { 10, 20 },
{ 30 },
{ 40 },
{ 50, 60, 70, 80 },
{ 90, 100, 110, 120, 130, 140, 150 } }; //declaring the array of the //integer type with different dimensions at different index values
int row_bound = ar.length; //declaring a integer variable and assigning the //length of the given array
int column_bound1 = ar[0].length; //declaring an integer variable and //assigning the length of the 0th index of the given array
int column_bound2 = ar[1].length; //declaring an integer variable and //assigning the length of the 1st index of the given array
int column_bound3 = ar[2].length; //declaring an integer variable and //assigning the length of the 2nd index of the given array
int column_bound4 = ar[3].length; //declaring an integer variable and //assigning the length of the 3rd index of the given array
int column_bound5 = ar[4].length; //declaring an integer variable and //assigning the length of the 4th index of the given array
System.out.println("printing the dimensions of the given array”);
System. out.println("The Dimension 1 is: " + row_bound);
System. out.println("The Dimension 2 is: " + column_bound1);
System. out.println("The Dimension 3 is: " + column_bound2);
System. out.println("The Dimension 4 is: " + column_bound3);
System. out.println("The Dimension 5 is: " + column_bound4);
System. out.println("The Dimension 6 is: " + column_bound5);
}
}
Output:
Printing the dimensions of the given array
The Dimension 1 is: 5
The Dimension 2 is: 2
The Dimension 3 is: 1
The Dimension 4 is: 1
The Dimension 5 is: 4
The Dimension 6 is: 7