赞
踩
class FunctionDemo
{
/* 数组的定义
1、同一种数据类型的集合,其实数组就是一个容器
2、可以自动给数组中的元素从0开始自动编号,方便操作这些元素
3、数组格式:
数据类型[] 数组名 = new 元素类型[元素个数或数组长度]
int [] arr = new int[3]
4、一旦建立,必须明确数组长度
*/
public static void main(String[] args)
{
int [] arr = new int[3];
arr[0] =80;
System.out.println(arr[0]);
}
}
class FunctionDemo
{
/*数组操作常见问题
n
*/
public static void main(String[] args)
{
/*数组超出索引范围
1、当访问到数组中不存在的角标时发生如下异常:
ArrarIndexOutOfBoundsExceptio
*/
int arr[] = new int[3];
System.out.println(arr[3]);
/*
当引用型变量没有任何实体指向时,还在用其操作实体,就会发生如下异常 :[无指针指向]NullPointerException
*/
arr =null;
Sytem.out.println(arr[0]);
/*
*/
System.out.println(arr); //打印的是数组在堆内存的地址值 ,哈希表
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。