java 数组声明方法

时间:2023-03-10 01:54:38
java 数组声明方法
 //数组
public class Test16{
public static void main(String args[]){ //声明一:
int [] x;
x = new int[3];//为数组申请内存空间,3个
x[0]=10;
x[1]=20;
x[2]=30;
//求数组的长度;
int len=x.length;
System.out.println("变量x的长度:"+len); //声明二:
int [] xx=new int[3];//定义一个数组并申请好内存空间
xx[0]=10;
xx[1]=100;
xx[2]=200; //声明三:
int [] y=new int[]{10,20,30,40};
//int len=x.length;
System.out.println("变量y的长度:"+y.length); }
}