Java - una submatriz

 
Vista:

una submatriz

Publicado por MARY (31 intervenciones) el 17/11/2006 16:06:23
hola tengo este codigo y no se como hacer que submatriz sea una matriz por favor ayudenme, lo que quiero hacer es una submatriz de otra matriz pero tengo que usar interface

si coloco XMatriz submatriz [][]= new Matrices(); o XMatriz submatriz[f][c] = new Matrices();
tambien me da error .asi como lo tengo me da error cuando le voy a asignar
valores submatriz[i-filaDesde][j]=mat[i][j];

POR FAVOR AYUDA, QUE LA NECESITO MUCHO

public class Datos {
public int valor;
public boolean marca;
public Datos() {
valor=9;
marca=false;

public interface XMatriz {
public Datos mat [][];
public int f=0, c=0;
public XMatriz XMatriz(int filaMax, int colMax);
//crea un matriz de tamaño máximo filaMax x colMax
public XMatriz rangoFilas(int filaDesde, int filaHasta);// throws XMatrizException;
//devuelve una submatriz de filas
}

public class Matrices implements XMatriz {
public Datos mat[][];
int f,c;
public Matrices() {
mat= new Datos[f][c];
}
public XMatriz XMatriz(int filaMax, int colMax) {
f=filaMax;
c=colMax;
mat = new Datos[f][c];
Datos inicio = new Datos();
for (int i=0; i<filaMax; i++)
for (int j=0; j<colMax; j++)
mat[i][j]= inicio;
}
public XMatriz rangoFilas(int filaDesde, int filaHasta)
{
XMatriz submatriz = new Matrices(); // COMO HAGO PARA QUE submatriz SEA UNA MATRIZ
for (int i=filaDesde; i<=filaHasta; i++)
for (int j=0; j<c; j++)
submatriz[i-filaDesde][j]=mat[i][j];
return (submatriz);
}
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder