- 傳統(tǒng)方式
int[] num = {1, 8, 7, 5, 6, 9, 2, 3};
for(int i=0; i<num.length; i++) {
System.out.print(num[i] + " ");
}
- for each 循環(huán)
int[] num = {1, 8, 7, 5, 6, 9, 2, 3};
for(int element: num)
System.out.print(element + " ");
- Arrays.toString() 方法
int[] num = {1, 8, 7, 5, 6, 9, 2, 3};
System.out.println(Arrays.toString(num));
- 二維數(shù)組輸出方法類似
參考文章:https://blog.csdn.net/chenkaibsw/article/details/78989459