Accessing and updating the values of a 2D array

In Java, accessing and updating values in a 2D array is done using the row and column indices. The general format is:

- **Accessing a value**: array[row][column]
- **Updating a value**: array[row][column] = newValue;

image

Popcorn Hack 1 (Part 2)

  • Update the values of the array, you made in part 1 to the group members in another group
//Hack - Dinesh Sahai

String [][] myTable = {
    {"Dinesh", "Tanay"},
    {"Nisarg", "Imaad"}
};

myTable[0][0] = "Kayden";
myTable[0][1] = "Srijan";
myTable[1][0] = "Ian";
myTable[1][1] = "Tarun";


String solution = "Kayden";

for (int i=0; i < myTable.length; i++) {
    for (int j=0; j < myTable[i].length; j++) {
        if (myTable[i][j].equals(solution)) {
            System.out.println("Found at index: [" + i + "][" + j + "]");
        }
    }
}
Found at index: [0][0]