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
Step: 1
Get Instant Access with AI-Powered 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