gpt4 book ai didi

java - 如何以编程方式在二维数组中插入值?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:59:02 25 4
gpt4 key购买 nike

我想在 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
}
}

关于java - 如何以编程方式在二维数组中插入值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10751603/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com