Hi everyone! This is my first time posting on this website. I'm a beginner in java. I am facing a problem solving the following:
"A magic square is an arrangement of the numbers from 1 to n^2 (n-squared) in an nxn matrix, with each number occurring exactly once, and such that the sum of the entries of any row, any column, or any main diagonal is the same. It is not hard to show that this sum must be n(n^2+1)/2. Magic squares have been around since 650 BC (China) ! For those who are interested, this Wikipedia article provides more background.
You should add code to Magic.java to check that each column equals the n(n^2+1)/2. Currently, the Magic.java program does an incomplete job of determining all the necessary checks for satisfying the conditions of a Magic Square. In particular, it does not check that the sum of each column equals n(n^2+1)/2 You may find it useful to look at how the row sums were computed."
Here's the code for the magic square:
I would really appreciate any help! Thank you in advance!
posted 2 weeks ago
p.s.: ignore all the TODO's comments. I only need what is mentioned in the quotations at the beginning.
I would have thought that if you have an array in which the rows, columns, and diagonals all summed to n(n^2+1)/2 then it would automatically have n instances of the numbers from 1 to n. But I don't have a proof of that, nor do I have a counterexample. Any takers?
Milan, I'm sure that's part of your requirements to write that code. So I'm not saying you shouldn't write it. You definitely should. Don't pay any attention to my math diversion.
And by the way there's an error in the code following that comment. But if I'm right then it won't actually make any difference.
There's also an error in the comment.
A "dutch baby" is not a baby. But this tiny ad is baby sized:
global solutions you can do in your home or backyard