Matrices in java ()

0

In a Matrix the moment I enter a number for example one (1) the rest of the row is filled in at zero. ç

public Bidimensional (int f, int c){
      mat= new int [f][c];
}
    public int[][] matriz ( int col,int fil){
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < col; j++) {

             mat[i][j] =Integer.parseInt( JOptionPane.showInputDialog("Ingrese su voto para el canditado " + "A[" + i + "][" + j + "] " ));

            }
        }
        return mat;
    }
    
asked by Rayan 24.01.2018 в 00:44
source

1 answer

0

You fill it with 0 not because java fill it in when you enter a number, but with the simple fact of creating a matrix, java puts a default 0 in all spaces of the matrix. If you return the values you expected and some extra zeros is that when creating the matrix did not indicate the dimensions well, therefore you have created a larger matrix by filling all the holes with zeroes by default.

    
answered by 24.01.2018 в 16:32