package iotest;
import java.util.*;
import java.io.*;
import java.io.BufferedWriter;
import java.io.FileWriter;
public class ReadMatrix
{
public static void main(String [] args) throws IOException
{
for(int k =0; k<8; k++ )
{
String file_name = "C:/temp/testMatrix.txt";
ReadFile result = new ReadFile(file_name);
int numberOfLines = ReadFile.readLines();
String[] testFile = result.openFile();
int temp1 = 0;
int temp2 = 0;
int temp3 =0;
int temp4 = 0;
int size = 0;
int [] dimension = new int [1];
//Find the value of dimension of matrix
for(int i =temp3; i<temp3+1; i++)
{
try
{
dimension[temp4] = Integer.parseInt(testFile[i]);
size = dimension[temp4];
System.out.println("Dimension of Matrix is :"+ size );
ReadFile.writeTextFile("C:/temp/testOutPutDeterminant.txt", "Dimension of Matrix is :");
} catch (NumberFormatException nfe) {};
}
// create arrays for the matrices
String[] test2 = new String[size];
String[] [] test2A = new String[test2.length] [size];
int [] [] test2B = new int [test2.length][size];
for(int i = temp3+1; i <= temp3 + size ; i++)
{
System.out.println(testFile[i]);
test2 [temp2] = testFile[i];
temp2++;
temp1 = i;
}
temp2 = 0;
temp3 = temp1++;
System.out.println("Determinant of the above matrix is: ");
// creating a multi dimension array
int r = 0;
for (String test : test2)
{
test2A[r++] = test.split("\\s");
}
// convert a array of string into an array of integer
for (int i = 0; i < test2A.length; i++)
{
for(int j = 0; j < test2A.length; j++)
{
try {
test2B[i][j] = Integer.parseInt(test2A[i][j]);
} catch (NumberFormatException nfe) {};
}
}
System.out.println(Determinant.findDeterminant(tes t2B));
ReadFile.writeTextFile("C:/temp/testOutPutDeterminant.txt", "Final");
} // for loop ends
//temp3 = 0;
}
}//