-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathTraverseArray.java
More file actions
29 lines (29 loc) · 879 Bytes
/
TraverseArray.java
File metadata and controls
29 lines (29 loc) · 879 Bytes
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
public class TraverseArray {
public static void main(String[] args) {
// int arr[] = new int[5];
// for (int i = 0; i < arr.length; i++) {
// System.out.println(arr[i]);
// }
// Enhance for loop (Java 1.5)
// for (int ele : arr) {
// System.out.println(ele);
// }
// int arr[][] = new int[3][2];
int arr[][] = new int[3][];
arr[0] = new int[10];
arr[1] = new int[20];
arr[2] = new int[30];
for (int a[] : arr) {
for (int ele : a) {
System.out.print(ele + " ");
}
System.out.println();
}
// for (int i = 0; i < arr.length; i++) {
// for (int j = 0; j < arr[i].length; j++) {
// System.out.print(arr[i][j] + " ");
// }
// System.out.println();
// }
}
}