JAVA数组的遍历,使用了新的遍历方法foreach

Linux大全评论856 views阅读模式
  1. import Java.util.Arrays;  
  2. /** 
  3.  * 数组的遍历,使用了新的遍历方法foreach 
  4.  * @author HAN 
  5.  * 
  6.  */  
  7. public class ArrayDispApps {  
  8.   
  9.     public static void main(String[] args) {  
  10.         int arr1[]=new int[]{2,3,4,6,7};  
  11.         int arr2[]=Arrays.copyOf(arr1, arr1.length);  
  12.       
  13.         for(int x:arr2){ // foreach application   
  14.             System.out.print(x+" ");  
  15.         }  
  16.           
  17.         arr1[0]=55;  
  18.         System.out.println();  
  19.         for(int x:arr1){  
  20.             System.out.print(x+" ");  
  21.         }  
  22.           
  23.         System.out.println();  
  24.         for(int x:arr2){  
  25.             System.out.print(x+" ");  
  26.         }  
  27.   
  28.     }  
  29.   
  30. }  

企鹅博客
  • 本文由 发表于 2019年7月20日 13:50:47
  • 转载请务必保留本文链接:https://www.qieseo.com/173233.html

发表评论