227k views
2 votes
Create a method called fixArray(int[][] array, int row, int col, int value) that sets the [row][column] to the correct value. Then, call the fixArray method three times - once for each value change that you are supposed to make.

User Andy Li
by
6.1k points

1 Answer

2 votes

Answer:

  1. public class Main {
  2. public static void main (String [] args) {
  3. int[][] myArray = {{1,5,6}, {7, 9, 2}};
  4. fixArray(myArray, 1, 2, 12);
  5. System.out.println(myArray[1][2]);
  6. }
  7. private static void fixArray(int[][] array, int row, int col, int value){
  8. array[row][col] = value;
  9. }
  10. }

Step-by-step explanation:

The solution code is written in Java.

Firstly, create the method fixArray with that takes four inputs, array, row, col and value (Line 11). Within the method body, use row and col as index to address a particular element from array and set the input value to it (Line 12).

Next, we test the method in the main program using a sample array (Line 4) and we try to change the row-1 and col-2 element from 2 to 12 (Line 5).

The print statement in Line 7 will display 12 in console.

User BeeBand
by
5.9k points