Like in One Dimensional Array . Two Dimensional array also consists of sequence of elements.
But the elements can be laid in rectangular grid rather than a line.
We also have 2D Dynamic array Just as 1D Dynamic array https://techyield.blogspot.com/2019/06/introduction-to-dynamic-array.html
Let's take a look at an example of using a two-dimensional array:
package com.techyield.operationsinarray;
public class OperationsIn2Darray {
private static void printArray(int[][] a) {
for(int i =0; i < a.length; i++) {
System.out.println(a[i]);
}
for(int i = 0 ; i< a.length; i++) {
for(int k=0; a[i]!= null && k < a[i].length; k++) {
System.out.println(a[i][k]+" ");
}
System.out.println();
}
}
public static void main(String[] args) {
System.out.println("Example I:");
int [][] a = new int[2][];
printArray(a);
System.out.println(" Example 2:");
int [][] b = new int[3][5];
printArray(b);
System.out.println("Example 3:");
b[0] = new int[3];
b[1] = new int[5];
printArray(b);
}
}
No comments:
Post a Comment