I'm writing a program that creates a 2D array from a integer n. I then have to fill the array with values from 1 to the n*n array size and check to see if it is a magic square. The way I am doing it now fills the array in order from 1 to n*n array size. How can I make that random?
My code:
System.out.print("Enter an whole number: ");
int n = scan.nextInt();
int [][] magic = new int [n][n];
for (int row = 0; row < magic.length; row++)
{
for(int col = 0; col < magic[row].length; col++)
magic[row][col] = ((row * n) + 1) + col;
}