use java to solve Have the construction of the 2D integer array magic square take place in a public static method getMagicSquare that takes in an integer n as a parameter and returns the 2D integer array magic square as specified. Your main method should perform input and output (I/O) and call this method to perform the computation. Create a class MagicSquare that prompts the user for a positive odd integer size, generates a normal magic square of order size, and prints it with numbers right-justified and aligned in evenly-spaced columns. You may assume the numbers in the square are 3 digits or less (i.e. size ≤ 31). However, each space-separated column should have a width equal to the largest integer in the magic square. (See example transcripts below.) To generate the magic square, use the following algorithm: Assign 1 to our initial current position: the bottom row, middle column. Place each successive value (up to size * size) in the first of the following positions that is unoccupied: (1) one space down and to the right, or (2) one space up. Positions wrap around the sides, top and bottom, as shown in the following example transcripts (user input underlined):
use java to solve Have the construction of the 2D integer array magic square take place in a public static method getMagicSquare that takes in an integer n as a parameter and returns the 2D integer array magic square as specified. Your main method should perform input and output (I/O) and call this method to perform the computation.
Create a class MagicSquare that prompts the user for a positive odd integer size, generates a normal magic square of order size, and prints it with numbers right-justified and aligned in evenly-spaced columns. You may assume the numbers in the square are 3 digits or less (i.e. size ≤ 31). However, each space-separated column should have a width equal to the largest integer in the magic square. (See example transcripts below.)
To generate the magic square, use the following
Step by step
Solved in 4 steps with 3 images