-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMultiDimensionArray.java
69 lines (45 loc) · 1.53 KB
/
MultiDimensionArray.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package practice;
public class MultiDimensionArray {
//declaration
int darr[][];
int[] darr1[];
int[][] darr2[];
//declaration, instantiation and initialization
static String[][] languages={{"Java","C","C#"},{"Ruby","phython","As400"},
{"PHP","c++","JavaScript"},{"","",""}};
//Array declaration, instantiation// array created with maximum size of
//3 rows and columns
static int[][] numbers= new int[3][3];
public void PassingDataToArray(){
//
int i;
int number=0;
//Outer array is pass the control to each row one by one until last row
for(i=0; i<numbers.length;i++){
//inner array is for inserting the data to each column of current row
for(int j=0;j<numbers[i].length;j++){
numbers[i][j]=number;
number++;
}
}
}
public void iterateTheArrayData(int[][] arr){
//Outer array is pass the control to each row one by one until last row
for(int i=0; i<arr.length;i++){
//inner array is for reading the data from each column of current row
String holder="";
for(int j=0;j<arr[i].length;j++){
//System.out.println(arr[i][j]);
holder=holder+"\t "+arr[i][j];
}
System.out.println(holder);
}
}
public static void main(String[] args){
MultiDimensionArray obj = new MultiDimensionArray();
System.out.println(numbers.length+" is the Row size of this array");
System.out.println(+numbers[0].length +" is the column size of first row");
obj.PassingDataToArray();
obj.iterateTheArrayData(numbers);
}
}