You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public void repopulate() {
// iterate through each row of the grid
for (int row = 0; row < grid.length; row++) {
// iterate through each column of the current row
for (int col = 0; col < grid[row].length; col++) {
// initialize a random value that meets the criteria
int value;
do {
// generate a random value between 1 and MAX (inclusive)
value = (int) (Math.random() * MAX) + 1;
} while (value % 10 != 0 || value % 100 == 0); // ensure value is divisible by 10 but not 100
// assign the valid value to the current grid element
grid[row][col] = value;
}
}
}
b)
public int countAscendingCols() {
// initialize a counter to track columns in ascending order
int ascendingCount = 0;
// iterate through each column in the grid
for (int col = 0; col < grid[0].length; col++) {
boolean isAscending = true;
// check if the current column is in ascending order
for (int row = 1; row < grid.length; row++) {
if (grid[row][col] < grid[row - 1][col]) {
isAscending = false; // set to false if a descending value is found
}
}
// increment the counter if the column is in ascending order
if (isAscending) {
ascendingCount++;
}
}
// return the total number of ascending columns
return ascendingCount;
}
The text was updated successfully, but these errors were encountered:
a)
public void repopulate() {
// iterate through each row of the grid
for (int row = 0; row < grid.length; row++) {
// iterate through each column of the current row
for (int col = 0; col < grid[row].length; col++) {
// initialize a random value that meets the criteria
int value;
do {
// generate a random value between 1 and MAX (inclusive)
value = (int) (Math.random() * MAX) + 1;
} while (value % 10 != 0 || value % 100 == 0); // ensure value is divisible by 10 but not 100
}
b)
public int countAscendingCols() {
// initialize a counter to track columns in ascending order
int ascendingCount = 0;
}
The text was updated successfully, but these errors were encountered: