开发者

Extract data from 2d array java

开发者 https://www.devze.com 2023-02-24 04:04 出处:网络
How can i extract data from a 2d array.. e and b are indexes of the array int e = IO.readInt(); int b = IO.readInt();

How can i extract data from a 2d array.. e and b are indexes of the array

int e = IO.readInt();

        int b = IO.readInt();

        int a[][] = { { 8, 2, 6, 5 }, // row 0
                { 6, 3, 1, 0 }, // row 1
        开发者_开发知识库        { 8, 7, 9, 6 } };

        for (int i = 0; i < a.length; i++) {

            for (int j = 0; j < a[0].length; j++) {

                a[i][j] = i;

                System.out.print(a[i][j] + " ");
            }
            System.out.println("");
        }`enter code here` 


You can think of a 2D array like a table. If you visualize it this way, your array a[] would look like this:

8 2 6 5
6 3 1 0
8 7 9 6

Then to access the elements in the array, you have to provide the row number and the column number:

    0 1 2 3
   --------
0 | 8 2 6 5
1 | 6 3 1 0
2 | 8 7 9 6

So, for example, in row 0, column 3 is the number 5. In code this would look like a[0][3].

Technically speaking, a 2D array is actually an array of arrays, but it's often easier to think of it as a table.


More details would be nice but I'll take a stab (in the dark) at it ...

a[e][b]
0

精彩评论

暂无评论...
验证码 换一张
取 消