Problems with array printing

Asked

Viewed 39 times

0

Matriz Principal:

public static String [][] matrizPrincipal(){
        String [] [] matriz = new String [2] [6];
        matriz[0][0] = "Robin Arryn";
        matriz[0][1] = "Lino Facioli";
        matriz[0][2] = "145";
        matriz[0][3] = "Vivo";
        matriz[0][4] = "Arryn";
        matriz[0][5] = "Feminino";
        
        matriz[1][0] = "Yohn Royce";
        matriz[1][1] = "Rupert Vansittart";
        matriz[1][2] = "45";
        matriz[1][3] = "Vivo";
        matriz[1][4] = "Arryn";
        matriz[1][5] = "Feminino";
        return matriz;
    }

Method that selects the names of the characters that are Female and are in the Arryn family:

public static String imprimeMatrizFeminina(String [] [] mat){
        int cont = 0;
        for(int i=0; i<mat.length; i++){
            if(mat[i][5].equals("Feminino") && mat[i][4].equals("Arryn")) cont ++;
        }
        String[] matrizFemininaArryn = new String [cont];
        for(int i=0; i<mat.length; i++){
            if(mat[i][5].equals("Feminino") && mat[i][4].equals("Arryn")) matrizFemininaArryn[i] = mat[i][0];
            System.out.println("Mulheres da família Arryn:" + Arrays.toString(matrizFemininaArryn));
        }
        return "";
    }

Part of the main that calls this method:

case 6:
                String matrizMulheres = imprimeMatrizFeminina(mat);
                System.out.println(matrizMulheres);
                break;

Can anyone tell me why this is happening?

http://puu.sh/hQUAf/aa3a16bc7a.png

The second impression is correct, but because the first?

DETAIL: I will have to make an impression for each family in the same method, so I am not using Return. That is, all Feminine, separated by families.

1 answer

1

Solved. Just move the println out of the for

  • Mark the V below the answer voting field. This will indicate that this answer solves the problem.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.