Help with Magic square program

I'm writing a program that will take in a user-inputed 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):

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;

}

I check row sums first, taking the complete sum of all the rows and if that is not divisible by the number of rows, it means that not all the sums were the same so it returns false (not a magic square). I attempted to do the same sort of procedure with the columns but I can't control the indices the same because they jump by row (don't increase by one each time). How should I deal with that? And how should I go about checking the diagonals?

Thanks. Any help appreciated.