声明并初始化数组
int[] numbers = {1, 2, 3, 4, 5};
使用`new`运算符
int[] numbers = new int;numbers = 1;numbers = 2;numbers = 3;numbers = 4;numbers = 5;
使用循环设置元素
int[] numbers = new int;for (int i = 0; i < numbers.length; i++) {numbers[i] = i + 1;}
使用`Arrays`工具类
int[] numbers = new int;Arrays.fill(numbers, 10);

对于多维数组,赋值方法类似:
声明并初始化多维数组
int[][] matrix = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
使用嵌套循环逐个赋值
int[][] array = new int;for (int i = 0; i < array.length; i++) {for (int j = 0; j < array[i].length; j++) {array[i][j] = i + j;}}
使用静态赋值初始化多维数组
int[][] array = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
以上是Java中设置数组值的一些常见方法。请根据您的具体需求选择合适的方法
