java遍历数组练习(for循环、foreach)
/*
* 遍历数组 for循环 foreach
* */
public class Test01 {public static void main(String[] args) {int[] arr = {11,3,45,6,78,89,23,4};//for循环遍历数组for (int index = 0;index<arr.length;index++){System.out.print(arr[index]+"\t");}System.out.println();//foreach循环遍历数组for (int x:arr) {System.out.print(x+"\t");}}
}
执行代码如下: