Java中創建數組的幾種方法


Java中創建數組的幾種方法

public static void main(String[] args) {
//創建數組的第一種方法
int[] arr=new int[6];
int intValue=arr[5];
//System.out.println(intValue);
//創建數組的第二種方法
int[] x={1,2,3,4};
//System.out.println(x[1]);

//創建數組的第三種方法。
int[] y= new int[]{1,2,3,4,5};
int m=0;
boolean length = isLength(m,y);
if(length){
System.out.println(y[m]);
}else{
System.err.println("數組標越界");
}

}
//判斷數組下標是否越界
public static boolean isLength(int m,int arr[]){
boolean flag=false;
int length = arr.length;
if(m<length)
flag=true;
return flag;
}

原文博客的鏈接地址:https://cnblogs.com/qzf/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM