理想的には、値を見つけたらカウンターを停止するのが理想的です。プログラムを実行すると、マトリックス内の他の値の比較が続けられます。2D配列LinearSearch Sorted List
public static void LinearSearch1(int[][] matrix, int array_size, int target) {
int row, col;
int comparison_counter = 0;
boolean found = false;
while (!found)
{
for (row = 0; row < array_size; row++)
{
for (col = 0; col < array_size; col++)
{
comparison_counter++;
if (matrix[row][col] == target)
{
found = true;
}//end if
}//end inner for
}//end outer for
} //end while
System.out.println(target + " found in " + comparison_counter + " number of comparisons using linear search");
}
それはタイプミスでした、ありがとう! –