Question: Write a method called isMagic which takes in a 2D integer array. The function returns True if all rows and columns sum to the same
Write a method called isMagic which takes in a 2D integer array. The function returns True if all rows and columns sum to the same value, and False if they do not. 8, 1, 6 3, 5, 7 4, 9, 2 The above array will return True because all rows and columns sum to 15. If we change index [2][0] to 7 then it would return False: 8, 1, 6 3, 5, 7 7, 9, 2 Now the first column and the last row both sum to 18, while all other rows and columns sum to 15. Since not all rows and columns sum to the same number it returns False. (Note if you're familiar with magic matrices in math that I've left out checking the diagonal for this problem.)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
