tengo un problema he intentado leer números complejos desde un txt en java la información del txt es la siguiente:
2 //Numero de columnas
2 //Numero de filas
1.0+2.0i, 3.0+4.0i
1.0+2.0i, 3.0+4.0i
He implementado la siguiente función para tratar de leer el numero complejo, donde en consola me da el siguiente error:
incompatible types: String cannot be converted to COMPLEJO
Mi código es el siguiente:
class COMPLEJO
{
//Declaracion de atributos
private float real;
private float imaginario;
//Definicion de los metodos:
//Metodo constructor
COMPLEJO() //Constructor por default.
{
real = 0;
imaginario = 0;
System.out.println("Se ha ejecutado el contrsuctor por defecto");
}
//Constructor con parametros.
COMPLEJO(float r, float i)
{
real = r;
imaginario = i;
}
COMPLEJO(float r)
{
real = r;
imaginario = 0;
}
}
class MATRIZCOMPLEJA
{
private COMPLEJO [][]Mx; //Variable de referencia.
private int M; //Filas
private int N; //Columnas
public void LeerMatrizCompleja() throws FileNotFoundException
{
String archivo = "pruebaMatrices.txt";
Scanner Lectura;
Lectura = new Scanner(new File(archivo));
int M, N, i, j;
MATRIZCOMPLEJA MatrizA[][];
MATRIZCOMPLEJA MatrizB[][];
System.out.println("Numero de filas: ");
M = Lectura.nextInt();
System.out.println(M);
System.out.println("Numero de columnas: ");
N = Lectura.nextInt();
System.out.println(N);
MatrizA = new MATRIZCOMPLEJA[M][N];
for(i=0; i<M; i++)
{
for(j=0; j<N; j++)
{
Mx[i][j] = Lectura.nextLine();
System.out.println(MatrizA[i][j] + " \t");
}
}
MatrizB = new MATRIZCOMPLEJA[M][N];
for(i=0; i<M; i++)
{
for(j=0; j<N; j++)
{
Mx[i][j] = Lectura.nextLine();
System.out.println(MatrizB[i][j] + " \t");
}
}
}
}
Ya he intentado usar next, hasNext, nextLine usando patrones pero consigo el mismo error.