二维数组的相关知识
1.从定义形式上看:int [] []
2.从概念上理解:之前一维数组里面的元素是单个数据组合,而二维数组里面的数据是多个一维数组的组合
如何访问二维数组;
访问第(i+1)个一维数组的第(j+1)个值:arr[i] [j]
一、二维数组的使用
使用方式1:动态初始化
语法:类型 [ ] [ ] 数组名 = new 类型 [大小] [大小]
比如:int [ ][] a=new int [2][3]
1 public class twoArry{ 2 public static void main(String[] args){ 3 /* 4 二维数组 5 int[i][j];表示访问第i+1个数的第j+1个数 6 */ 7 //定义一个新的3行4列二维数组 8 int[][] rays= new int [3][4]; 9 rays [2][3] =6;//给rays数组第3行第4个数赋值6; 10 // 遍历二维数组 11 for (int i=0;i<rays.length ;i++ ) { 12 for (int j = 0;j<rays[i].length ;j++ ) { 13 System.out.print(rays[i][j]+" "); 14 } 15 System.out.println(); 16 } 17 } 18 }
想多了都是问题,做多了才是答案