To fill a two-dimensional array in Java, you can use a loop to iterate over the elements of the array and assign values to them.
Here's an example of how to do it:
public class Main {
public static void main(String[] args) {
int[][] array = new int[3][3];
// Fill the array with values
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array[i].length; j++) {
array[i][j] = i * 3 + j;
}
}
// Print the array
for (int[] row : array) {
System.out.println(Arrays.toString(row));
}
}
}
This code creates a two-dimensional array of size 3x3 and fills it with values using a nested loop. The inner loop iterates over the elements of each row, and the outer loop iterates over the rows.
You can use a similar approach to fill a two-dimensional array with any type of data. Just make sure to use the appropriate type for the array and the values you are assigning to it.