public class test{
public static void main(String[] args){
int[] arr={1,2,3,4,5,6,7,8,9};
System.out.println("数组arr[1,2,3,4,5,6,7,8,9]");
System.out.print("遍历后的数组:[");
traverse(arr);
}
public static void traverse(int[] arr){
for(int i=0;i<arr.length;i++){
if(i==arr.length-1){
System.out.println(arr[i]+"]");
}
else{
System.out.print(arr[i]+",");
}
}
}
}
输出结果:
数组arr[1,2,3,4,5,6,7,8,9]
遍历后的数组:[1,2,3,4,5,6,7,8,9]