day05-数组的内存图解&数组越界异常
This commit is contained in:
33
day05/src/com/inmind/Demo02_array_memory.java
Normal file
33
day05/src/com/inmind/Demo02_array_memory.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package com.inmind;
|
||||
/*
|
||||
数组的操作
|
||||
二进制:0~1
|
||||
八进制:0~7
|
||||
十进制:0~9
|
||||
十六进制:0~15, 0~9 10(a)、11(b)、12(c)、13(d)、14(e)、15(f)
|
||||
*/
|
||||
public class Demo02_array_memory {
|
||||
public static void main(String[] args) {
|
||||
//定义一个数据不确定的长度为3的存放整型的数组
|
||||
int[] arr = new int[3];
|
||||
System.out.println(arr);//[I@50cbc42f
|
||||
/*
|
||||
[I@50cbc42f
|
||||
[I:表示当前是一个数组数据类型,数组存放的数据类型是int
|
||||
50cbc42f:表示数组在内存中开辟的空间地址
|
||||
|
||||
索引:操作数组指定空间的值,从0开始
|
||||
*/
|
||||
|
||||
System.out.println(arr[0]);//0
|
||||
System.out.println(arr[1]);//0
|
||||
System.out.println(arr[2]);//0
|
||||
double[] dArr = new double[3];
|
||||
System.out.println(dArr[0]);//0.0
|
||||
System.out.println(dArr[1]);//0.0
|
||||
System.out.println(dArr[2]);//0.0
|
||||
System.out.println("-------------------");
|
||||
//注意:数组的最大索引= 数组.length -1;
|
||||
//System.out.println(dArr[3]);//(数组越界异常)java.lang.ArrayIndexOutOfBoundsException: Index 3 out of bounds for length 3
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user