diff --git a/src/Matrix.java b/src/Matrix.java index a8284c3..c62b760 100644 --- a/src/Matrix.java +++ b/src/Matrix.java @@ -23,7 +23,7 @@ public class Matrix { public Matrix(int[][] matrix) { this.matrix = matrix; rowLength = matrix.length; - columnLength = rowLength; + columnLength = matrix[0].length; } public Matrix multiply(Matrix m) { @@ -66,13 +66,12 @@ public class Matrix { matrix = new int[rowLength][columnLength]; - for(int columnIndex = 0; line != null && columnIndex < matrix.length; columnIndex++, line = br.readLine()) { + for(int columnIndex = 0; line != null; columnIndex++, line = br.readLine()) { lineArray = line.split(";"); for(int rowIndex=0; rowIndex < matrix[columnIndex].length; rowIndex++) { matrix[rowIndex][columnIndex] = Integer.parseInt(lineArray[rowIndex]); } } - br.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { diff --git a/src/TestMatrix.java b/src/TestMatrix.java index faff181..4e14b85 100644 --- a/src/TestMatrix.java +++ b/src/TestMatrix.java @@ -3,12 +3,12 @@ public class TestMatrix { Matrix matrix = new Matrix("/home/old/projects/Java/graphprogram/24n_01.csv"); Matrix scalarProduct; - System.out.println(matrix.getRowLength()); - System.out.println(matrix.getColumnLength()); + System.out.println("RowLength: " + matrix.getRowLength()); + System.out.println("ColumnLength: " +matrix.getColumnLength()); - System.out.println(matrix); + System.out.println("\nMatrix A: \n" + matrix); scalarProduct = matrix.multiply(matrix); - System.out.println(scalarProduct); + System.out.println("\nScalarProduct A²: \n" + scalarProduct); } }