Have students write a program that constructs an n x n Magic Square in Java so they gain practice working with bounds in 2D arrays.

Like 
  • A Magic Square is an arrangement of the numbers from 1 to n2 (n-squared) in an n × n matrix with each number occurring exactly once, such that the sums of the entries of any row, column, or main diagonal are the same.
    • Some of this assignment is very tricky. Students will need to carefully plan how their program will handle going out of bounds in the array.
  • Download Josh Pudaloff’s Magic Square exercise handout for a detailed explanation of the algorithm.