Question: Magic Squares. A magic square is a square array of numbers consisting of the distinctpositive integers1, 2, ...,n 2 arranged such that the sum of

Magic Squares.

A magic square is a square array of numbers consisting of the distinctpositive integers1, 2, ...,n2arranged such that the sum of thenumbers in any horizontal, vertical, ormaindiagonal line is always the same number known as themagic constant.

You can read more about them here: https://mathworld.wolfram.com/MagicSquare.html

a class called MagicSquare, clear itand copythe codebelowinto your program. Complete methods checkRowSum and checkColSumusing nested for-loops.checkRowSum needs to check sum of each row with magic constant and return true ifsum of everyrowisequal to it, else return false. checkColSum needs to check sum of each column with magic constant and return true ifsum of every column is equal to it, else return false.

Sample run1:

Enter a 3 X 3 magic square:

2 7 6

9 5 1

4 3 8

Enter the magic constant: 15

----------------------------------------------

It has distinct integers 1 through 9.

Sum of every row equals 15.

Sum of every column equals 15.

Sum of 2 main diagonals equals 15.

->It is a magic square with magic constant of 15.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!