0
I created a matrix and put it to initialize with the values passed in the constructor, but it is not initializing. I created the object, played the values, but when I call the method to show the matrix, it does not appear, as if it had not been created. Someone can help me?
import java.util.Scanner;
public class ExerMatriz {
Scanner s = new Scanner(System.in);
private int linha;
private int coluna;
ExerMatriz(){
System.out.println("Digite a quantidade de linhas");
this.setLinha(s.nextInt());
System.out.println("Digite a quantidade de colunas");
this.setColuna(s.nextInt());
}
private int m[][] = new int[this.getLinha()][this.getColuna()];
public void mostrarMatriz(){
for(int i=0; i< m.length;i++){
for(int j=0; j<m[0].length;j++){
System.out.print(this.m[i][j]);
}
System.out.println();
}
}
public int[][] getM() {
return m;
}
public void setM(int[][] m) {
this.m = m;
}
public int getLinha() {
return linha;
}
public void setLinha(int linha) {
this.linha = linha;
}
public int getColuna() {
return coluna;
}
public void setColuna(int coluna) {
this.coluna = coluna;
}
}
Diego, thank you very much. I thought earlier about what you said, that she was a servant, but I didn’t know how to do it. If you can only ask one more question... The second is, (int j=0; j<m[0].length;j++), picks up the column. However, [0]. length only picks up if it is of the same row dimension, correct? How do I if it’s different sizes?
– Thun An Freitas Chiu
Rereading your doubt, I realize I didn’t understand correctly, you can ask a new question to clarify this :)
– user28595