Initialising a multidimensional array in Java

前端 未结 8 900
小鲜肉
小鲜肉 2020-11-22 14:20

What is the correct way to declare a multidimensional array and assign values to it?

This is what I have:

int x = 5;
int y = 5;

String[][] myStringA         


        
8条回答
  •  花落未央
    2020-11-22 14:42

     int[][] myNums = { {1, 2, 3, 4, 5, 6, 7}, {5, 6, 7, 8, 9, 10, 11} };
     for (int x = 0; x < myNums.length; ++x) {
        for(int y = 0; y < myNums[i].length; ++y) {
           System.out.print(myNums[x][y]);
        }
     }
    

    Output

    1 2 3 4 5 6 7 5 6 7 8 9 10 11

提交回复
热议问题