0
public static boolean hasValue(int[][] arr, int value, int row)
{
    int column = arr[row].length; 
    for (int i = 0; i < column; i++) 
    { 
        if (arr[row][i] == value) 
        return true; 

    } 
    return false;
}

It's a boolean method, so if the given value exist in a given row, it will say true. java.lang.ArrayIndexOutOfBoundsException: 4

Ahmad Khan
  • 17
  • 5
  • What does your `int[][]` array look like? – code May 08 '21 at 01:38
  • I am under the impression that you have forgotten that arrays are 0 indexed. – Spectric May 08 '21 at 01:44
  • 1
    your for loop should be fine.. but are you sure the value you pass in for row is in bounds? test for 0 <= row < arr.length – DynasticSponge May 08 '21 at 01:44
  • Please read the help about providing a minimum, small, verifiable example. That is, a complete program that has the bug you're trying to fix. Then people will be able to help you. Otherwise, we're just guessing. – Gene May 08 '21 at 02:19

0 Answers0