我有二维数组(测试)和需要删除行数的二维数组(删除行)。问题是我创建的循环在我尝试打印测试数组时没有结果。我需要创建不包括第 0、1、3、4 行的新矩阵。
如何在 while 循环之外访问新数组?
import java.util.ArrayList;
import java.util.Arrays;
public class remove
{
public static void main( String[] args )
{
double[][] test = { { 100 }, { 200 }, { 300 }, { 400 }, { 500 }, { 600 }, { 700 },
{ 800 }, { 900 }, { 1000 } };
int[][] removeRow = { { 0 }, { 1 }, { 3 }, { 4 }, };
int reduce = 1;
int r = 0;
while ( reduce == 0 )
{
ArrayList<double[]> rowsToKeep = new ArrayList<double[]>( test.length );
for ( int i = 0; i < test.length; i++ )
{
if ( i != removeRow[0][0] - r )
{
double[] row = test[i];
rowsToKeep.add( row );
}
}
r++;
test = new double[rowsToKeep.size()][];
for ( int i = 0; i < rowsToKeep.size(); i++ )
{
test[i] = rowsToKeep.get( i );
}
reduce = removeRow.length - r;
r = r++;
System.out.println( Arrays.deepToString( test ) );
}
}
}
凤凰求蛊
相关分类