【java学习笔记7】一维数组、二维数组的循环遍历
一维数组遍历:
package array; public class ArrayTest01 { public static void main(String[] args) { // 静态初始化一维数组 int[] array1 = {1,2,3,4,5}; for (int i = 0;i < array1.length;i ++){ System.out.println(array1[i]); } // 动态初始化一维数组 int[] array2 = new int[5]; for (int j = 0;j < array2.length;j ++){ System.out.println(array2[j]); } } }
二维数组遍历:
package array; public class ArrayTest04 { public static void main(String[] args) { String[][] array = { {"java","python","c++"}, {"cat","dog","pig"}, {"Math","English","History"} }; // 遍历二维数组 for (int i = 0; i < array.length; i++) { for (int j = 0;j < array[i].length;j++){ System.out.print(array[i][j]+" "); } System.out.println(); } } }
执行结果是:
java python c++
cat dog pig
Math English History
---------------------------------------------------
立足软件测试领域,并重新定义测试!
---------------------------------------------------