0

Im trying to make a method that return true if the value of mat[r][k] is positive, but the error-message say "The method println(int) in the type PrintStream is not applicable for the arguments (int[][], int, int)

The call on the method:

public static void main(String[] args) {

int[][] matrix = { { 1, 2, 3 }, { 4, -5, 6 }, { -7, 8, 0 } };

    System.out.println(isPositive(matrix), 2, 3);


}

The method:

public static String isPositive(int[][] mat, int r, int k) {
r--;
k--;

boolean value = false;

 for (int i = 0; i < mat.length; i++) {
    for (int j = 0; j < mat[i].length; j++) {

        if (mat[r][k] > 0) {
            value = true;
        }
    }
}
String out = "(" + mat[r][k] + ") : " + value;
return out;
}
j97
  • 1

1 Answers1

0

I think you just have your parentheses in the wrong place. The line of code below is calling isPositive with just matrix, but it expects 2 more int parameters:

System.out.println(isPositive(matrix), 2, 3);

When I ran it this way, I got the error:

method isPositive in class Test cannot be applied to given types;
    System.out.println(isPositive(matrix), 2, 3);
                       ^
required: int[][],int,int
found: int[][]
reason: actual and formal argument lists differ in length

You should be able to just change it to this code below:

System.out.println(isPositive(matrix, 2, 3));

Now, it's calling isPositive with the 3 args it expects, then returning to the println. I did this and ran it, and got this output: (6) : true.

CShark
  • 1,562
  • 1
  • 16
  • 27