-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrays2d.java
More file actions
38 lines (30 loc) · 1.11 KB
/
Arrays2d.java
File metadata and controls
38 lines (30 loc) · 1.11 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
public class Arrays2d {
public static void main(String[] args) {
// 2D arrays
// String[] fruits = {"apple", "banana", "watermelon"};
// String[] vegetables = {"onion", "capsicum", "beans"};
// String[] meats = {"chicken", "mutton", "ham", "fish"};
String[][] groceries = {{"apple", "banana", "watermelon"},
{"onion", "capsicum", "beans"},
{"chicken", "mutton", "ham", "fish"}};
groceries[0][0] = "pineapple";
for(String[] foods : groceries) {
for(String food : foods) {
System.out.print(food + " ");
}
System.out.println();
}
System.out.println();
// Telephone numberpad
char[][] telephone = {{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'}};
for(char[] rows : telephone) {
for(char cols : rows) {
System.out.print(cols + " ");
}
System.out.println();
}
}
}