53. for-each 遍历
语法讲解
今天学: Java 有增强 for 循环(for-each),可以更简洁地遍历数组。
public class Main {
public static void main(String[] args) {
int[] arr = {3, 8, 1, 9, 4};
int max = arr[0];
for (int x : arr) {
if (x > max) {
max = x;
}
}
System.out.println(max);
}
}
小练习
输出是什么?
提交要求: 只提交最终输出结果,不要添加多余的说明或引号。
全部评论