java定义数组的三种类型总结_错误提示

三种定义数组的格式如下:

int[] arr1=new int[10];

int[] arr2={1,2,3,6};

int[] arr3=new int[]{1,2,3,4,5,6,7,22};

注意:数组的length是一个属性,而字符串的length()是一个方法了!!!虽然都是求的他们各自的长度

package 第四天;

public class 数组 {public void showArray(int[] arr)

{for(int i=0;i

System.out.print(arr[i]+"\t");

System.out.println();}

public static void main(String[] args) {

int[] aa;

//System.out.println(aa);//只是声明了数组没赋初值不能使用会报错误提示),如果new出来了,则系统复int型的值全为0

int[] arr1=new int[10];//必须指定大小

int[] arr2={1,2,3,6};

System.out.println(arr2[0]);

int[] arr3=new int[]{1,2,3,4,5,6,7,22}注意,不能指定大小,这个最常用

数组 shuzu=new 数组frNPUgC();

shuzu.showArray(arr1);

shuzu.showArray(arr2);

shuzu.showArhttp://ray(arr3);

shuzu.showArray(new int[]{1,3,2,33});//可以,正确的赋值

//shuzu.showArray({2,4,1});//错误,报的是编译错误}}

System.out.print(arr[i]+"\t");

System.out.println();}

public static void main(String[] args) {int[] aa;

//System.out.println(aa);//只是声明了数组没赋初值不能使用会报错误提示),如果new出来了,则系统复int型的值全为0

int[] arr1=new int[10];//必须指定大小

int[] arr2={1,2,3,6};

System.out.println(arr2[0]);

int[] arr3=new int[]{1,2,3,4,5,6,7,22};http:注意,不能指定大小,这个最常用

数组 shuzu=new 数组frNPUgC();

shuzu.showArray(arr1);

shuzu.showArray(arr2);

shuzu.showArhttp://ray(arr3);

shuzu.showArray(new int[]{1,3,2,33});//可以,正确的赋值

//shuzu.showArray({2,4,1});//错误,报的是编译错误