Howdy. Let's discuss Magic Squares. 

Mark, Logan, Daniel, Jared, Qin, Hallie, Adam, Gabriela, Morgan, Paul, Zac,
Yiming, Jingzhe, Nick, Grant, MAR, Jack, Trevor, Phoebe, William, Jaquelyn,
James, Brennan, Lauren, Judy, Mohan, Jon, Alex Ong ... 

public class Magic {
  public static void main(String[] args) {
    int[][] a = { {1, 2} , {3, 4, 5}, {6} };
    Magic.show( a ); 
  }
  public static void show(int[][] a) {
    for (int row = 0; row < a.length; row++) { 
      for (int col = 0; col < a[row].length; col++) {
        System.out.print( a[row][col] + " " );    
      }
      System.out.println(); 
    }
      
  }
}

It runs like this:

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> run Magic
1 2 
3 4 5 




Here's how we get started:

public class Magic {
  public static void main(String[] args) {
    int size = 3; 
    int[][] magic = Magic.create(size); 
    Magic.show( magic ); 
  }
  public static int[][] create(int size) {
    int[][] result = new int[size][size];
    
    return result; 
  }
  public static void show(int[][] a) {
    for (int row = 0; row < a.length; row++) { 
      for (int col = 0; col < a[row].length; col++) {
        System.out.print( a[row][col] + " " );    
      }
      System.out.println(); 
    }    
  }
}

Here's the answer:

public class Magic {
  public static void main(String[] args) {
    int size = 3; 
    int[][] magic = Magic.create(size); 
    Magic.show( magic ); 
  }
  public static int[][] create(int size) {
    int[][] result = new int[size][size];
    int row = size-1, col = size/2; 
    int number = 1 ; 
    while (number <= size * size) {
      result[row][col] = number; 
      number = number + 1; 
      int i = (row + 1) % size, 
          j = (col + 1) % size; 
      if (result[i][j] > 0) {
        row = row -1; 
      } else {
        row = i; 
        col = j; 
      }
      Magic.show( result ); 
      System.out.println("------------------"); 
    }
    return result; 
  }
  public static void show(int[][] a) {
    for (int row = 0; row < a.length; row++) { 
      for (int col = 0; col < a[row].length; col++) {
        System.out.print( a[row][col] + " " );    
      }
      System.out.println(); 
    }    
  }
}

This is how it works:

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> run Magic
0 0 0 
0 0 0 
0 1 0 
------------------
0 0 2 
0 0 0 
0 1 0 
------------------
0 0 2 
3 0 0 
0 1 0 
------------------
4 0 2 
3 0 0 
0 1 0 
------------------
4 0 2 
3 5 0 
0 1 0 
------------------
4 0 2 
3 5 0 
0 1 6 
------------------
4 0 2 
3 5 7 
0 1 6 
------------------
4 0 2 
3 5 7 
8 1 6 
------------------
4 9 2 
3 5 7 
8 1 6 
------------------
4 9 2 
3 5 7 
8 1 6 


I can run it for size = 5 and it ends in 

------------------
11 18 25 2 9 
10 12 19 21 3 
4 6 13 20 22 
23 5 7 14 16 
17 24 1 8 15 


https://www.cs.indiana.edu/classes/c212-dgerman/spr2015/exam001.jpg

https://www.cs.indiana.edu/classes/c212-dgerman/spr2015/exam002.jpg

public class Mode {
  public static void main(String[] args) {
    int[] a = { 1, 2, 1, 4, 3, 3, 3, 4, 4, 2, 1, 5, 2, 4, 1, 4, 3, 4, 3 }; 
    System.out.println( Mode.mode( a ) ); 
  }
  public static int count(int[] a, int n) {
    int c = 0; 
    for (int e : a) 
      if (n == e)
        c = c + 1; 
    return c; 
  }
  public static int mode(int[] a) {
    int max = 0, freq = 0; 
    for (int e : a) {
      if (Mode.count(a, e) > freq) {
        max = e; 
        freq = Mode.count(a, e); 
      }
    }
    return max; 
  }
}

If I run this I get 4 as the answer. 

public class P611 {
  public static void main(String[] args) {
    int[] a = { 1, 4, 9, 16, 9, 7, 4, 9, 11};
    int[] b = { 11, 1, 4, 9, 16, 9, 7, 4, 9};
    int[] c = { 11, 11, 7, 9, 16, 4, 1, 4, 9};
    System.out.println( P611.sameElements(a, b) ); // true 
    System.out.println( P611.sameElements(a, c) ); // false
  }
  public static int count(int[] a, int n) {
    int c = 0; 
    for (int e : a) 
      if (n == e)
        c = c + 1; 
    return c; 
  }
  public static boolean sameElements(int[] a, int[] b) {
    for (int e : a)
      if (P611.count(a, e) != P611.count(b, e))
        return false; 
    for (int e : b)
      if (P611.count(a, e) != P611.count(b, e))
        return false;     
    return true;     
  }
}

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> run P611
true
false


--