Declare and initialize a two dimensional array of size 5x5 to 0.
nonsense = report
Share
Declare and initialize a two dimensional array of size 5x5 to 0.
nonsense = report
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Answer:
int[][] array = new int[5][5];
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array[i].length; j++) {
array[i][j] = 0;
}
}
Explanation:
This code creates a 2D array of size 5x5 and initializes all its elements to 0. The outer loop iterates over the rows of the array, while the inner loop iterates over the columns of each row. Within the inner loop, the value of each element is set to 0 using the assignment statement array[i][j] = 0;. After this loop completes, the 2D array array is fully initialized to 0.