一维数组的动态和静态写法
/**
* 一维数组的几种写法
*/
// 1 动态输入
int[] arr = new int[5];
arr[0] = 75 ;
arr[1] = 65 ;
arr[2] = 71 ;
arr[3] = 55 ;
arr[4] = 95 ;
// 2 静态输入
int[] str = new int[] {0,5,9,6,8,1,7,3};
// 3 静态输入
int[] sort = {1,5,9,6,8,7,3,2};
二维数组的动态和静态写法
/**
* 二维数组的几种写法
* 二维数组相当于大数组中,带有多个小数组,小数组的长度不固定,看情况自己需要写入
*/
int[][] score = new int[3][];
/* 第一种 动态输入
score[0] = new int[3] ;
score[1] = new int[3] ;
score[2] = new int[3] ;
score[0][0] = 1 ;
score[0][1] = 99 ;
score[0][2] = 89 ;
score[1][0] = 2 ;
score[1][1] = 89 ;
score[1][2] = 98 ;
score[2][0] = 3 ;
score[2][1] = 78 ;
score[2][2] = 68 ;
*/
// 第二种动态输入
score[0] = new int[] {1,78,89} ;
score[1] = new int[] {2,96,59};
score[2] = new int[] {3,79,99};
//静态输入,不写长度,直接写入,二维
int[][] arr = new int [][] {{1,2,3},{9,5,6,7},{8,1,4}} ;