遍历数组

public class xun {
public static void main(String[] args) {
int[] scores= {1,2,3,5};
int len=scores.length;
//for 循环遍历
for(int i=0;i<len;i++) {
int score=scores[i];
System.out.println(score);
}
//for each 遍历
System.out.println("for each 遍历");
for(int x:scores) {
System.out.println(x);
}
//可变参数 参数的最后一个参数可以是可变参数
System.out.println("可变参数");
print(1,2,3,5);
}
public static void print(int... x) {
int len=x.length;
for(int i=0;i<len;i++) {
System.out.println(x[i]);
}
}

原文地址:https://www.cnblogs.com/emma-zhu/p/9571771.html