我想在Java中动态地做到这一点。我知道如何在一维数组中插入值。我对二维数组有点困惑。

static final String shades[][] = {


 // Shades of grey
  {
    "lightgrey",
    "dimgray",
    "sgi gray 92",
  },
 // Shades of blue
  {
    "dodgerblue 2",
    "steelblue 2",
    "powderblue",
  },
// Shades of yellow
  {
    "yellow 1",
    "gold 1",
    "darkgoldenrod 1",
  },
 // Shades of red
  {
    "indianred 1",
    "firebrick 1",
    "maroon",
  }
};

最佳答案

String[][] shades = new String[intSize][intSize];
 // print array in rectangular form
 for (int r=0; r<shades.length; r++) {
     for (int c=0; c<shades[r].length; c++) {
         shades[r][c]="hello";//your value
     }
 }

09-10 08:41