-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreeArrayTest1.java
More file actions
57 lines (53 loc) · 1.37 KB
/
Copy pathThreeArrayTest1.java
File metadata and controls
57 lines (53 loc) · 1.37 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
47
48
49
50
51
52
53
54
55
56
57
package com.company.array;
/**
* @author 苏东坡
* @company 公司
* @create 2021-07-29-11:48 下午
*/
public class ThreeArrayTest1 {
public static void main(String[] args) {
/**
* 三维数组的遍历
*
*/
int[][][] arr = {{{1, 2, 3}, {4, 5}, {6}}};
/**
* 第一层普通for
* 第二层普通for
* 第三层普通for
*/
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
for (int k = 0; k < arr[i][j].length; k++) {
System.out.print(arr[i][j][k] + "\t");
}
}
System.out.println();
}
/**
* 第一层普通for
* 第二层普通for
* 增强for
*/
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
for (int num : arr[i][j]) {
System.out.print(num+"\t");
}
}
System.out.println();
}
/**
* 第一层增强for
* 第二层增强for
* 第三层增强for
*/
for (int[][] a : arr){
for (int[] b : a){
for (int num : b){
System.out.print(num+"\t");
}
}
}
}
}