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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started