在Java中,可以通过以下方式定义和赋值二维数组:
// 定义一个二维数组,包含3行和4列
int[][] twoDArray = new int[3][4];
// 给二维数组赋值
twoDArray[0][0] = 1;
twoDArray[0][1] = 2;
twoDArray[0][2] = 3;
twoDArray[0][3] = 4;
twoDArray[1][0] = 5;
twoDArray[1][1] = 6;
twoDArray[1][2] = 7;
twoDArray[1][3] = 8;
twoDArray[2][0] = 9;
twoDArray[2][1] = 10;
twoDArray[2][2] = 11;
twoDArray[2][3] = 12;
也可以在定义二维数组的同时进行赋值:
int[][] twoDArray = {
{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12}
};