import java.util.Scanner;
class Demo2
{
public static void main(String[] args){
//方式一
int[][] arr=new int[3][2];
System.out.println(arr);
System.out.println(arr[0]);
System.out.println(arr[1]);
System.out.println(arr[2]);
System.out.println(arr[0][0]);
System.out.println(arr[0][1]);
//方式二
int[][] arr1=new int[3][];
arr1[0]=new int[2];
arr1[1]=new int[3];
arr1[2]=new int[1];
System.out.println(arr1);
System.out.println(arr1[0]);
System.out.println(arr1[1]);
System.out.println(arr1[2]);
System.out.println(arr1[0][0]);
System.out.println(arr1[1][0]);
//方式三
int[][] arr2={{1,2,3},{4,5},{6}};
System.out.println(arr2);
System.out.println(arr2[0]);
System.out.println(arr2[1]);
System.out.println(arr2[2]);
System.out.println(arr2[0][0]);
System.out.println(arr2[1][1]);
}
}
Java二维数组
最新推荐文章于 2024-04-16 21:12:00 发布