Caso um post semelhante a esse já exista, eu peço desculpas.
Considere uma matriz com os seguintes elementos:
1 1 1
2 2 2
3 3 3
Deve-se fazer um vetor de objetos do tipo Linha com tamanho igual a 3.
Cada objeto individual do tipo linha, ficará com um linha da matriz.
Então linha[1] ficará com 1,1,1
linha [2] ficará com 2,2,2
Eu gostaria de saber com eu implemento isso em java.
Segue o código (há erros)
package matriximplementation;
public class MatrixImplementation {
public static void main(String[] args) {
// TODO code application logic here
int[][] m1 = {1,1,1},{2,2,2},{3,3,3};
Linha[] linha = new Linha[3];
//Passe linha 1 para o objeto linha[1], passe linha 2 para o obj linha[2] e etc.
for (int i = 0; i < linha.length; i++) {
for (int j = 0; j < linha.length; j++) {
for (int k = 0; k < linha.length; k++) {
linha[i] = new Linha(m1, j, k, (j + 3), (k + 3));
}
}
}
}
}
package matriximplementation;
public class Linha {
// Para cada objeto em Linha, será montada uma matriz de 1 por 3(uma linha e três colunas)
static int[][] matrizinterna;
static int x, y, linha, coluna;
public Linha(int[][] matriz, int x, int y, int linha, int coluna) {
matrizinterna = matriz;
this.x = x;
this.y = y;
this.linha = linha;
this.coluna = coluna;
}
// retorno da matriz??
}