package com.accp.test;
import java.util.Random;
public class Demo1 {
public static void main(String[] args) throws Throwable {
//数组元素
String[] strA={"a","c","d","e","f","g"};
String[] strB;
strB=strA;
for (int i = 0; i < strB.length; i++) {
System.out.println(strB[i]);
}
//随机数获得数组大小,class和newInstance来获得类的实例
int[] a=new int[Random.class.newInstance().nextInt(20)];
//多维数组
int[][] num=new int[][]{
// {1,2,3},
// {5,6,4},
// {7,8,9},
{3,4},
{7,8},
{1,2},
};
for (int i = 0; i < num.length; i++) {
for (int j = 0; j < num[i].length; j++) {
System.out.println("num["+i+"]["+j+"]"+"========="+num[i][j]);
}
}
//定义三维数组元素值,未定义大小
int[][][] abc=new int[][][]{
{
{1,2,3},
{4,5,6},
},
{
{7,8,9},
{10,11,12},
},
{
{13,14,15},
{16,17,18},
},
};
//三维数组循环遍历
for (int i = 0; i < abc.length; i++) {
for (int j = 0; j < abc[i].length; j++) {
for (int j2 = 0; j2 < abc[i][j].length; j2++) {
System.out.println("abc["+i+"]["+j+"]["+j2+"]"+"=========="+abc[i][j][j2]);
}
}
}
System.out.println("");
//定义数组,这里定义数组的大小,是3维数组
Integer[][] xls=new Integer[3][];
for (int i = 0; i < xls.length; i++) {
//这里根据Integer[3]定义数组是次维数组数,也就是单个数组里有多少个元素
xls[i]=new Integer[4];
for (int j = 0; j < xls[i].length; j++) {
xls[i][j]=new Integer(i+j);
}
}
for (int i = 0; i < xls.length; i++) {
for (int j = 0; j < xls[i].length; j++) {
System.out.println("xls["+i+"]["+j+"]"+"============"+xls[i][j]);
}
}
System.out.println("");
}
}