增强型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?p=61135