Matrix with sublocks in Java

0

Good, I have a problem with a matrix in java, the issue is that I have to make a matrix 10X10 where within it has different sublocks all the outer edge is block A, and the interior minus 16 central cells is the block B, those 16 central cells should be eliminated since they can not be used, but I do not know how to do it once I create the matrix I do not know how to reference each subloque with a variable char that represents block A and block B. I also do not know how to eliminate those internal cells. What I have to represent is just like the image, being the block of dark orange color the block A and the block of light orange the block B and the black block that is the one that I do not have to consider, since these are cells of prisoners and the black block is the internal courtyard therefore it should not be taken into account. I do not know if it's better to define Block as another class since I have the Jail class and Prisoner, or it would be better to block it as an attribute of Cell, but what if I have to have differentiated both block A and block B

    
asked by Floppy 15.12.2018 в 20:25
source

1 answer

1

If you mean this:

String[][] matriz = new String[10][10];


    for(int i = 0; i < matriz.length; i++){
        for(int j = 0; j < matriz[0].length;j++){
            if(i==0||i==matriz.length-1||j==0 ||j==matriz[0].length-1){
                matriz[i][j] = "A";
                System.out.print(matriz[i][j]);
            }else if(!((i>=3&&i<=6)&&(j>=3&&j<=6))){
                matriz[i][j] = "B";
                System.out.print(matriz[i][j]);
            }else {
                System.out.print(" ");
            }
        }
        System.out.println();
    }

The result is:

AAAAAAAAAA
ABBBBBBBBA
ABBBBBBBBA
ABB (PATIO) BBA
ABB (PATIO) BBA
ABB (PATIO) BBA
ABB (PATIO) BBA
ABBBBBBBBA
ABBBBBBBBA
AAAAAAAAAA

A matrix is a container of values, if you do not want values to be stored in one position, store them in another, but eliminating a "block" only because it does not work is not the best idea, since it is very possible that you need renew that code in the future.

In this case what I have done is ignore the blocks in the center.

    
answered by 15.12.2018 / 21:15
source