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;
}
I think you just have your parentheses in the wrong place. The line of code below is calling
isPositivewith justmatrix, but it expects 2 moreintparameters:When I ran it this way, I got the error:
You should be able to just change it to this code below:
System.out.println(isPositive(matrix, 2, 3));Now, it's calling
isPositivewith the 3 args it expects, then returning to theprintln. I did this and ran it, and got this output:(6) : true.