public class Demo1 {
public static void main(String[] args) {
int[] arr = { 10, 29, 3, 49, 59 };
// 遍历--for循环:
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
// 遍历--for加强版 foreach
/*
* for(数据类型 变量:数组或者集合){ 变量--->数组中的元素 }
*/
for (int n : arr) {
System.out.println(n);
}
String[] str = { "234", "asd34", "qwer", "wer", "asdf" };
for (String s : str) {
System.out.println(s);
}
}
}
一维数组遍历
最新推荐文章于 2024-03-06 00:02:49 发布