Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java:if语句,它跳过下面的if语句_Java_Arrays_If Statement_Arraylist_Continue - Fatal编程技术网

java:if语句,它跳过下面的if语句

java:if语句,它跳过下面的if语句,java,arrays,if-statement,arraylist,continue,Java,Arrays,If Statement,Arraylist,Continue,我有一个2D字符串数组,通过它我将逐行查找最小值。当我找到最小值时,我正在将找到的最小值的行添加到ArrayList中,以便在下一次迭代中跳过该行,以找到数组的第二个最小值。我一直这样做,直到每个行号都是ArrayList的一部分 请参阅我的代码: List assignedRow = new ArrayList(); for(int t = 0; t < excelMatrix.length-1; t++){ double lowest = Double.parseDou

我有一个2D字符串数组,通过它我将逐行查找最小值。当我找到最小值时,我正在将找到的最小值的行添加到ArrayList中,以便在下一次迭代中跳过该行,以找到数组的第二个最小值。我一直这样做,直到每个行号都是ArrayList的一部分

请参阅我的代码:

List assignedRow = new ArrayList();    
for(int t = 0; t < excelMatrix.length-1; t++){    
double lowest = Double.parseDouble(excelMatrix[0][1]);
    int row = 0, column = 0;    

    for(int r = 0; r < excelMatrix.length-1; r++){                      
        if(assignedRow.contains(r) == true) continue;               
        for(int c = 1; c < excelMatrix[r].length; c++){             
            double value = Double.parseDouble(excelMatrix[r][c]);
            if(lowest > value) {
                lowest = value;
                row = r;    
                column = c; 
            }   
        }   
    } 
    assignedRow.add(row);
}
List assignedRow=new ArrayList();
对于(int t=0;t值){
最低=数值;
row=r;
列=c;
}   
}   
} 
assignedRow.add(行);
}
到目前为止,代码运行良好,直到最小值出现在第0行。之后,它总是执行continue条件

我现在正在寻找允许我返回for循环的东西,使用下一个更高的r,它不是ArrayList的一部分

我希望我把问题说清楚。

我希望这能奏效

  List assignedRow = new ArrayList();
    double lowest = 0;
    while (assignedRow.size() < excelMatrix.length) {

        // find intial lowest value from non assign row to compare
        for (int t = 0; t < excelMatrix.length - 1; t++) {
            if (!assignedRow.contains(t)) {
                lowest = Double.parseDouble(excelMatrix[t][0]);
                break;
            }
        }

        int row = 0, column = 0;
        for (int r = 0; r < excelMatrix.length - 1; r++) {
            if (assignedRow.contains(r)) continue;
            for (int c = 0; c < excelMatrix[r].length; c++) {
                double value = Double.parseDouble(excelMatrix[r][c]);
                if (lowest > value) {
                    lowest = value;
                    row = r;
                    column = c;
                }
            }
        }
        assignedRow.add(row);
    }
List assignedRow=new ArrayList();
双最低=0;
while(assignedRow.size()值){
最低=数值;
row=r;
列=c;
}
}
}
assignedRow.add(行);
}

如果最低值存储在任何行的第一列,则代码将不起作用,因为您将从列索引1开始迭代(循环
int c=1的第三个
lovel=Double.parseDouble(excelMatrix[0][1]

只是一个旁注(这不是问题):
if(assignedRow.contains(r)==true)如果(assignedRow.contains(r))
contains
已经返回了一个
布尔值,你不需要使用
==true
来获得一个。我的意思是,如果((assignedRow.contains(r)==true)==true)
if((assignedRow.contains(r)==true)==true)==true)
?;-)恐怕我不太明白您想做什么。
如果(assignedRow.contains(r)==true)
将只跳过那些已经具有最小值的行。如果最小值和第二最小值相同,则会出现问题row@T.J.Crowder他想在
2D
数组中找到最小值,然后是第二个最小值,依此类推,但忽略他已经找到的行(这是我从这个问题中得到的)@T.J.Crowder问题是,如果最小值在第0行,0位于ArrayList内,因此不会执行for循环的其余部分。我总是需要知道一行的最小值,这行中的其他值都是无关的,这就是我跳过它们的原因。但是,例如,如果第一个最小值在第0行,我无法在数组中找到任何其他最小值,因为它总是执行“continue”。