java 从二维数组java中提取数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5613891/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 11:54:53  来源:igfitidea点击:

Extract data from 2d array java

javaarrays

提问by user647207

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

我如何从二维数组中提取数据.. e 和 b 是数组的索引

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` 

回答by basszero

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

更多细节会很好,但我会(在黑暗中)刺伤它......

a[e][b]

回答by Computerish

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

你可以把二维数组想象成一张桌子。如果您以这种方式a[]将其可视化,您的数组将如下所示:

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].

因此,例如,在第 0 行,第 3 列是数字 5。在代码中,这看起来像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.

从技术上讲,二维数组实际上是数组的数组,但通常更容易将其视为表格。