增强型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 }
原文地址:https://www.cnblogs.com/zhuangbijingdeboke/p/12078338.html
时间: 2024-10-30 10:53:47