public String toString() {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < board.length; i++){
        for (int j = 0; j < board[i].length; j++){
            Position pos = new Position(i, j);
            if (pos.equals(pacmanPosition)) sb.append('P');
            else {
                sb.append(board[i][j]);
            }
        }
        sb.append("\n");
    }
    return sb.toString();
}

// OU

public String toString() {
    String  res = "";
    for (int i = 0; i < board.length; i++){
        for (int j = 0; j < board[i].length; j++){
            Position pos = new Position(i, j);
            if (pos.equals(pacmanPosition)) res += 'P';
            else {
                res += board[i][j];
            }
        }
        res += "\n";

    }
    return res;
}