a java problem

Status
Not open for further replies.

shivi4

Journeyman
please tell how to implement this program in java

Q2.Magic Squares.An n*n matrix that is filled with the numbers 1,2,...,n*n is a
magic square if the sum of the elements in each row ,in each column,and in the
two diagonals is the same value . For example
16 3 2 13
5 10 11 8
9 6 7 12
4 15 14 1
Write a program that reads in n*n values from the keyboard and tests whether
they form a magic square when put into array form.You need to test three
features:
->Did the user enter n*n numbers for some n?
->Does each of the numbers 1,2...,n*n occur exactly once in the user input?
->When the no.s are put into a square , r the sums of the rows , columns and
diagonals equal to each other?
If the size of the input is a square,test whether all no.s between 1 and n are
present.Then compute the row , column, and diagonal sums.
 

sakumar79

Technomancer
task 1: is it necessary to use a termination character to stop the inputs or are u planning to ask user number of entries at the start? If latter, you can ask directly number of rows/columns and take that as n
task 2: i think you can use binary sort on a duplicate array and then check each number with the next in the list to ensure no two numbers are repeated.
task 3: this should be a no-brainer

Arun
 
Status
Not open for further replies.
Top Bottom