java 一维数组与二维数组的遍历

一维数组:

//原有for循环

String[] arr = {"tom","rosi","sunny"};

for(int i=0;i

System.out.println(arr[i]);

}

//新式for循环

for(String s : arr){

System.out.println(s);

}

二维数组:

String[][] arr = {{"tom","American"},{"rosi","England"},{"张三","china"}};

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();//打印一个元素后换一行

}

你可能感兴趣的:(javase)