Codehs 8.1.5: Manipulating 2d Arrays

I don't have access to CodeHS's specific problem "8.1.5 Manipulating 2D Arrays" directly, but this is a common exercise where you need to write code that modifies a 2D array in some way. Based on typical CodeHS problems, here are the most common variations of this exercise: public class Main { public static void main(String[] args) { int[][] array = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} }; // Increase each element by 1 for (int i = 0; i < array.length; i++) { for (int j = 0; j < array[i].length; j++) { array[i][j] += 1; } } // Print the result for (int i = 0; i < array.length; i++) { for (int j = 0; j < array[i].length; j++) { System.out.print(array[i][j] + " "); } System.out.println(); } } } Alternative Version: Doubling Each Element public class Main { public static void main(String[] args) { int[][] array = { {2, 4, 6}, {8, 10, 12}, {14, 16, 18} }; // Double each element for (int i = 0; i < array.length; i++) { for (int j = 0; j < array[i].length; j++) { array[i][j] *= 2; } } // Print the modified array for (int[] row : array) { for (int val : row) { System.out.print(val + " "); } System.out.println(); } } } Version with a Method: Manipulate2D Method public class Main { public static void main(String[] args) { int[][] arr = { {1, 2, 3}, {4, 5, 6} }; manipulate2D(arr); // Print to verify for (int[] row : arr) { for (int val : row) { System.out.print(val + " "); } System.out.println(); } }

Закрыть
Закрыть
Ваш товар в корзине.
Перейти в корзину или продолжить покупки?
В корзину
Закрыть
Вход
Закрыть
Вход
Закрыть
Вход

Отправили код на ваш номер
Дождитесь звонка и введите 4 последние цифры номера
Код действует 10 минут

Закрыть
Регистрация
Пожалуйста, зарегистрируйтесь. Вы сможете: 👍
  • следить за историей и статусом заказов;
  • сохранять избранное;
  • не вводить повторно свои данные.
Нужно подтвердить. Пришлём код.
Телефон подтверждён.
В пароле должно быть: от 8 символов; цифры, латинские буквы, знаки препинания.
Войти, если уже регистрировались
Закрыть
Подтвердите номер телефона

Отправили код на номер
Дождитесь звонка и введите 4 последние цифры номера
Код действует 10 минут

Закрыть
Восстановление пароля
Через несколько минут на ваш почтовый ящик придет письмо со ссылкой на активацию аккаунта.
Закрыть