done
don't ask how
This commit is contained in:
parent
b16d900532
commit
51daa4a511
@ -1,42 +1,49 @@
|
|||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
|
||||||
public class Matrix {
|
public class Matrix {
|
||||||
private String[][] matrix;
|
private int[][] matrix;
|
||||||
public static void main(String[] args) {
|
|
||||||
|
public static void main(String[] args) {}
|
||||||
|
|
||||||
|
public Matrix(String file) {
|
||||||
|
matrix = this.readCSV(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[][] importCSV(String file) {
|
public int[][] readCSV(String file){
|
||||||
|
int[][] intMatrix = null;
|
||||||
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
|
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
|
||||||
String line = br.readLine();
|
String line = br.readLine();
|
||||||
int rowCount = 0;
|
int rowCount = line.trim().split(";").length;
|
||||||
int columnCount = line.split(";").length;
|
int columnCount = rowCount;
|
||||||
|
String[] lineArray = null;
|
||||||
|
|
||||||
while (line != null) {
|
intMatrix = new int[rowCount][columnCount];
|
||||||
line = br.readLine();
|
|
||||||
rowCount++;
|
for(int columnIndex = 0; line != null && columnIndex < intMatrix.length; columnIndex++, line = br.readLine()) {
|
||||||
|
lineArray = line.trim().split(";");
|
||||||
|
for(int rowIndex=0; rowIndex < intMatrix[columnIndex].length; rowIndex++) {
|
||||||
|
intMatrix[columnIndex][rowIndex] = Integer.parseInt(lineArray[rowIndex]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
matrix = new String[rowCount][columnCount];
|
|
||||||
|
|
||||||
br.close();
|
br.close();
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return matrix;
|
return intMatrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printCSV() {
|
public void print() {
|
||||||
for(int i=0; i < matrix.length; i++) {
|
for(int columnIndex=0; columnIndex < matrix.length; columnIndex++) {
|
||||||
for(int j=0; j < matrix[i].length; j++) {
|
for(int rowIndex=0; rowIndex < matrix[columnIndex].length; rowIndex++) {
|
||||||
System.out.print(matrix[i][j]);
|
System.out.print(matrix[columnIndex][rowIndex]);
|
||||||
}
|
}
|
||||||
System.out.println();
|
System.out.println();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
public class TestMatrix {
|
public class TestMatrix {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
testImportCSV();
|
test1("");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void testImportCSV() {
|
public static void test1(String file) {
|
||||||
Matrix m = new Matrix();
|
Matrix matrix = new Matrix(file);
|
||||||
|
|
||||||
m.importCSV("/home/satan/bin/graphprogram/graph.csv");
|
matrix.print();
|
||||||
m.printCSV();;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user