-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwoDimensionArray.java
More file actions
46 lines (32 loc) · 1.22 KB
/
TwoDimensionArray.java
File metadata and controls
46 lines (32 loc) · 1.22 KB
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
public class TwoDimensionArray {
// multidimensional arrays
// 2D arrays=> an array where each element is an array
// useful for matrix of data
public static void main(String [] args){
String [][] groceries={ {"fruits", "orange","banana"},
{"potato", "onion", "carrot"},
{"chicken", "pork","fish"}
};
// accessing a single element
// groceries[i][j]
// the fist index represents row the second represents columns
groceries[0][0]="pineapple";
groceries[2][1]="egg";
for(String[]foods:groceries){
for(String food:foods){
System.out.print(food+" ");
}
System.out.println();
}
char [][]telephone={{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}};
for (char []numbers:telephone){
for(char number :numbers){
System.out.print(number+" ");
}
System.out.println();
}
}
}