I am trying to make a three in a row and for this I have created a matrix, which is the board. My plan is that when it is the turn of a player, he specifies the row and column and in this one he has a 1 for Player 1 and a 0 for Player 2. Well, the problem I have is that once the row and column I get the error "incompatible types: int cannot be converted to int[][]" on return.
import java.util.Scanner;
public class Jugador1 {
private static Scanner t = new Scanner(System.in);
public static int[][] dato(int tab[][]){
System.out.println("-Jugador 1.");
System.out.println("--Fila: ");
int f = t.nextInt();
System.out.println("--Columna: ");
int c = t.nextInt();
return tab[f][c] = 1;
}
}
I know that the code is incomplete and that for example I need to discern if the row and column are between 1 and 3, but it was just a test to assign a value to an array.
What is happening to you is that when you write:
is returning an integer, the 1 you just assigned to position
tab[f][c]
, and not the array tab which is what the function expects as you defined it.You will have to do the assignment on one line, and the return of the array on another: