Results 1 to 3 of 3
Thread: Help with Magic square program
 02162011, 02:31 AM #1Member
 Join Date
 Nov 2010
 Posts
 28
 Rep Power
 0
Help with Magic square program
I'm writing a program that will take in a userinputed sequence and determine if what they entered is a magic square. So I need to test: 1) did the user enter n^2 numbers, 2) there are no repeated numbers, and 3) row, column, and diagonal sums are all the same. I am having trouble coming up with a way to do 1 and 3.
I am completely stumped on 1) but here is what I have for 3):
Java Code:int nrows, ncolumns, k = 0, rsum = 0, csum = 0; nrows = (int)Math.ceil(Math.sqrt((double) square.size())); ncolumns = nrows; for (int r = 0; r < nrows; r++) { while (k < ncolumns) { rsum += square.get(k); k++; } } if (rsum%nrows != 0) return false; k = 0; }
Thanks. Any help appreciated.
 02162011, 03:14 AM #2
 02162011, 04:10 PM #3Member
 Join Date
 Nov 2010
 Posts
 28
 Rep Power
 0
Similar Threads

Magic squares help
By mjpam in forum New To JavaReplies: 3Last Post: 06302010, 02:24 PM 
Need Help with Magic Square
By easybe in forum New To JavaReplies: 10Last Post: 04232010, 09:39 PM 
Magic square
By gandalf5166 in forum New To JavaReplies: 20Last Post: 04152010, 07:18 PM 
Magic Square!!!... :D
By joms999 in forum New To JavaReplies: 4Last Post: 02252010, 07:55 AM 
Problem using buttons to creat a magic square game
By goldman in forum New To JavaReplies: 5Last Post: 05052008, 04:04 AM
Bookmarks