//迭代器
@Test
public void demo4() {
ArrayList<Object> list = new ArrayList<>();
list.add(1);
list.add(3);
list.add(2);
list.add(4);
list.add(5);
Iterator<Object> iterator = list.iterator();
while (iterator.hasNext()) {
Object next = iterator.next();
System.out.println(next);
}
}
// 二维数组的叠加
@Test
public void demo3() {
int num = 0;
int[][] arr = { { 1, 2, 3, 4 }, { 1, 2, 3 } };
for (int x = 0; x < arr.length; x++) {
for (int y = 0; y < arr[x].length; y++) {
num += arr[x][y];
}
}
System.out.println(num);
}
时间: 2024-10-19 09:46:17