How do I instantiate a new matrix every iteration?
I am doing a custom written javabat problem that requires me to compare set length groups of numbers. I will describe the problem in deta开发者_StackOverflow社区il more if you need, but I want to know if there's a way to create a new matrix (with a new name every time; within a for loop) with the set length from the array's square rooted length (all arrays being passed in are perfect squares).
for (int boxes = 0; boxes < matrixBox; boxes++)
{
String matrixName = "matrixLine" + boxes+"";
int []matrixName = new int[matrixBox]; // The compiler wants to make a new variable.
}
I essentially need a new matrix with the names: matirixLine1, matrixLine2,...etc. so I can compare them later on to solve my problem.
Btw, this site is incredible.
You need to store the arrays in an array (an int[][]
)
For example:
int[][] data = new int[matrixBox][]; //Full of nulls
for (int index = 0; index < size; index++)
{
data[index] = new int[size];
}
精彩评论