数组系列教材 (四)- Java 中如何使用增强for循环 增强型for循环在遍历一个数组的时候会更加快捷 步骤1:增强型for循环步骤2:练习-最大值步骤3:答案-最大值 步骤 1 : 增强型for循环 注:增强型for循环只能用来取值,却不能用来修改数组里的值 public class HelloWorld { public static void main(String[] args) { int values [] = new int[]{18,62,68,82,65,9}; //常规遍历 for (int i = 0; i < values.length; i++) { int each = values[i]; System.out.println(each); } //增强型for循环遍历 for (int each : values) { System.out.println(each); } } } 更多内容,点击了解: https://how2j.cn/k/array/array-foreach/330.html