Java的增强for循环

增强型for循环只能用来取值,却不能用来修改数组里的值

 1 public class HelloWorld {
 2     public static void main(String[] args) {
 3         int values [] = new int[]{18,62,68,82,65,9};
 4         //常规遍历
 5         for (int i = 0; i < values.length; i++) {
 6             int each = values[i];
 7             System.out.println(each);
 8         }
 9          
10         //增强型for循环遍历
11         for (int each : values) {
12             System.out.println(each);
13         }
14          
15     }
16 }

猜你喜欢

转载自www.cnblogs.com/zhuangbijingdeboke/p/12078338.html