Java 数组声明
class demo06
{
public static void main(String[] args)
{
//创建数组
//1、数据类型[] 变量名 = new 数据类型[长度]
/*int[] arr = new int[3];
arr[0] = 1;
arr[1] = 2;
System.out.println(arr[0]);
System.out.println(arr[1]);
System.out.println(arr[2]);
System.out.println(arr);*/
//2、数据类型[] 变量名 = new 数据类型[]{值1,值2,……}
/*String[] arr = new String[]{"熊大","熊二","光头强"};
System.out.println(arr[0]);
System.out.println(arr[1]);
System.out.println(arr[2]);
System.out.println(arr);*/
//3、数据类型[] 变量名 = {值1,值2,……}
double arr[] = {1.4,6.3,7.3};
//或者 double[] arr ={1.4,6.3,7.3};
System.out.println(arr[0]);
System.out.println(arr[1]);
System.out.println(arr[2]);
System.out.println(arr);
//注意:1、数组长度不可变。如果访问不存在的数组,则数组越界异常
}
}