PlayJava Day016

Today Plant Science:

/ * 2019.08.19 started to learn, to make this shift. * /

Array

1. The one-dimensional array: Data Type [] = new variable name Data type [length]

LENGTH: array.length

To ensure that no more than array.length when using index - 1, ArrayIndexOutOfBoundsException run or prone to error

2. The two-dimensional array: Data Type [] [] = new variable name Data type [length Row] [length col]

For example: the results of several storage student three courses

Xiao Ming: language, mathematics, English

Xiaoqiang: language, mathematics, English

Red: language, mathematics, English

。。。。。。

int[ ][ ] arr = new int[3][4]

arr.length: get the number of one-dimensional array of the current two-dimensional array there ----> 3

arr [1] .length: obtaining two-dimensional array of the second length of the current row of the array ----> 4

arr [1] [2]: Access row subscripts 1, when the number of element data columns labeled 2 (second row, third column)

Traversing the two-dimensional array: double for loop

for(int i = 0 ; i < arr.length ; i++) {
    for(int j = 0 ; j < arr[i].length ; j++) {
        System.out.println(arr[i][j]) ;
    }
}

 

Guess you like

Origin www.cnblogs.com/JavaDemo01/p/11519279.html