I'm trying to print a 2d grid with random numbers and another equally sized grid with -1s in place of the numbers that are evenly divisible by 3. I finished pretty much everything, but I cant figure out how to make the following line work: Arraycopy = c.createCoords({10,10});
I'm know I'm supposed to call the method with an int[][], I just cant remember how.
Here's all of the code just in-case:
public class practice
{
public int [][] createArray(int rSize, int cSize)
{
Random r = new Random();
int[][] array = new int [rSize] [cSize];
for (int row = 0; row <array.length; row++)
{
for(int col = 0; col < array[0].length; col++)
{
array[row][col] = r.nextInt(25);
}
}
return array;
}
public void print2DArray(int[][] Array)
{
for (int row = 0; row <Array.length; row++)
{
for(int col = 0; col < Array[0].length; col++)
{
System.out.print(Array[row][col] + "\t");
}
System.out.println("\n");
}
}
public int[][] createCoords(int[][] Array)
{
int [] [] coord = {
{-1,-1,-1, -1, -1, -1, -1, -1, -1, -1},
{-1,-1,-1, -1, -1, -1, -1, -1, -1, -1},
{-1,-1,-1, -1, -1, -1, -1, -1, -1, -1},
{-1,-1,-1, -1, -1, -1, -1, -1, -1, -1},
{-1,-1,-1, -1, -1, -1, -1, -1, -1, -1},
{-1,-1,-1, -1, -1, -1, -1, -1, -1, -1},
{-1,-1,-1, -1, -1, -1, -1, -1, -1, -1},
{-1,-1,-1, -1, -1, -1, -1, -1, -1, -1},
{-1,-1,-1, -1, -1, -1, -1, -1, -1, -1},
{-1,-1,-1, -1, -1, -1, -1, -1, -1, -1}
};
for (int row = 0; row <coord.length; row++)
{
for(int col = 0; col < coord[0].length; col++)
{
System.out.print(coord[row][col] + "\t");
}
System.out.println("\n");
}
for (int row = 0; row <coord.length; row++)
{
for(int col = 0; col < Array[row].length; col++)
{
if(Array[row][col] %3 == 0)
coord[row][col] = -1;
}
}
return coord;
}
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
practice c = new practice();
int [][] myArray;
int [][] Arraycopy;
myArray = c.createArray(10, 10);
Arraycopy = c.createCoords({10,10});
c.print2DArray(Arraycopy);
c.print2DArray(myArray);
}
}
print2DArray(new int[][]{{1,2,2},{3,3,4}});