public class Test {

    public static void main(String[] args) {
 
       int[][] arr = {
          { 1, 2, 3 },
          { 4, 5, 6 },
          { 7, 8, 9 }
       };
 
       System.out.println("arr[0][0] = " + arr[0][0]);
       System.out.println("arr[1][2] = " + arr[1][2]);
       System.out.println("arr[2][1] = " + arr[2][1]);
       
    }
 
 }
 Test.main(null);
arr[0][0] = 1
arr[1][2] = 6
arr[2][1] = 8
// hack 1

public class Test {

    public static void main(String[] args) {
 
      String[][] arr = {
         { "a", "f", "g" },
         { "b", "e", "h" },
         { "c", "d", "i" }
      };
 
      // Print the last element in the array!
      System.out.println("arr[2][2] = " + arr[2][2]);
    }
 
 }
 Test.main(null);
arr[2][2] = i
// hack 2
public class Test {

    public static void main(String[] args) {
 
      String[][] arr = {
         { "Atlanta", "Baltimore", "Chicago" },
         { "Australia", "Boston", "Cincinnati" },
         { "Austin", "Beaumont", "Columbus" }
      };
      arr[2][0] = "Athens";
       // Change Austin to Athens and print!
      System.out.println("Change Austin to Athens and print!");
      
      System.out.println(arr[2][0]);
    }
 
 }
 Test.main(null);
Change Austin to Athens and print!
Athens
// hack 3

public class Test {

    public static void main(String[] args) {
 
       String[][] arr = {
          { "Atlanta", "Baltimore", "Chicago" },
          { "Australia", "Boston", "Cincinnati" },
          { "Austin", "Beaumont", "Columbus" }
       };
       for (int row = 0; row < 3; row++) {
         for (int col = 0; col < 3; col++) {
            System.out.print(arr[row][col] + " ");
         }
        System.out.println(" ");
      }
       // Print out the array without using numerical values!
       
    }
 
 }
 Test.main(null);
Atlanta Baltimore Chicago  
Australia Boston Cincinnati  
Austin Beaumont Columbus  
// searching for a value in a 2d array

public class Test {

    public static void main(String[] args) {
  
        String[][] arr = {
            { "Atlanta", "Baltimore", "Chicago" },
            { "Australia", "Boston", "Cincinnati" },
            { "Austin", "Beaumont", "Columbus" }
        };

        String match = "";
        String name = "Boston";
        for (String[] row : arr) {
            for (String item : row) {
                if (item.equals(name)) {
                    match = name;
                }
            }
        }

        if (match.length() == 0) {
            System.out.println("No Match!");
        } else {
            System.out.println(name);
        }
        
    }
 
 }
Test.main(null);
Boston
// hack 4

public class Test {

    public static void main(String[] args) {
  
        String[][] arr = {
            { "Atlanta", "Baltimore", "Chicago" },
            { "Australia", "Boston", "Cincinnati" },
            { "Austin", "Beaumont", "Columbus" }
        };

        String longest = arr[0][0];
        
        
        for (String[] row : arr) {
            for (String item : row) {
                if (item.length()>longest.length()) {
                    longest = item;
                }
            }
        }
        // Use nested for loops to find the longest or shortest string!
        System.out.println("Use nested for loops to find the longest or shortest string!: " + longest);
        
    }
 
 }
Test.main(null);
Use nested for loops to find the longest or shortest string!: Cincinnati

Homework

a) Write a static method findPosition that takes an integer value and a 2D integer array and returns the position of the integer in the given 2D integer array. If the integer is not an element of the 2D integer array, the method returns null. For example, assume that array arr is the 2D integer array shown at the beginning of the question. • The call findPosition(8, arr) would return the Position object (2,1) because the value 8 appears in arr at row 2 and column 1. • The call findPosition(17, arr) would return null because the value 17 does not appear in arr.

/** Returns a 2D successor array as described in part (b) constructed from intArr.
 * Precondition: intArr contains at least one row and contains consecutive values.
* Each of these integers may be in any position in the 2D array.
 */ 

 public static Position[][] getSuccessorArray(int[][] intArr) 
{
    Position[][] successor = new Position[intArr.length][intArr[0].length];
    for(int r=0;r<intArr.length;c++)
    {
        for(int c=0;c<intArr[0].length;c++)
        {
            Position p = findPosition(intArr[r][c]+1 , intArr);
            
        }
    }
}