Java数组定义声明的几种方法: 1.类型名称[]变量名称=new类型名称[length];
2 .类型名称[]变量名称={? (;
3 .类型名称[]变量名称=new类型名称[]{? (;
代码示例: public class example1{ publicstaticvoidmain [ string [] args ] { /数组定义的几种方法//1 .类型名称[ ]变量名称=new类型名称[length] int []a=new int[4]; a[0]=1; a[1]=2; a[2]=3; a[3]=4; 系统. out.println (a; system.out.println(a[0]; system.out.println(a[1]; system.out.println(a[2]; system.out.println(a[3]; //2 .类型名称[]变量名称={? (; int [ ] b={ 1,2,3,4 }; system.out.println(b[0]; system.out.println(b[1]; system.out.println(b[2]; 系统. out.println (b [3]; //3 .类型名称[]变量名称=new类型名称[]{? (; int [ ] c=new int [ ] { 1,2,3,6 }; system.out.println(c[0]; system.out.println(c[1]; 系统. out.println (c [2]; 系统. out.println (c [3]; }三种方法的概述如下: 1.类型名称[]变量名称=新类型名称[length];
//1 .类型名称[]变量名称=新类型名称[length]; int []a=new int[4]; a[0]=1; a[1]=2; a[2]=3; a[3]=4; 系统. out.println (a; system.out.println(a[0]; system.out.println(a[1]; system.out.println(a[2]; system.out.println(a[3]; 方法一:
2 .类型名称[]变量名称={? (;
//2 .类型名称[]变量名称={? (; int [ ] b={ 1,2,3,4 }; system.out.println(b[0]; system.out.println(b[1]; system.out.println(b[2]; 系统. out.println (b [3]; 方法二:
3 .类型名称[]变量名称=new类型名称[]{? (;
//3 .类型名称[]变量名称=new类型名称[]{? (; int [ ] c=new int [ ] { 1,2,3,6 }; system.out.println(c[0]; system.out.println(c[1]; 系统. out.println (c [2]; 系统. out.println (c [3]; 方法:
转载于:https://www.cn blogs.com/aihua dung/p/8525267.html