new method

This commit is contained in:
René Fuhry 2023-05-26 00:14:44 +02:00 committed by GitHub
parent 2448464ed4
commit 2de0ac5a02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -1,5 +1,6 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.util.Random;
import java.io.FileReader;
import java.io.FileNotFoundException;
@ -18,6 +19,7 @@ public class Matrix {
matrix = new int[rowLength][columnLength];
this.rowLength = rowLength;
this.columnLength = columnLength;
randomAdjazenzMatrix();
}
public Matrix(int[][] matrix) {
@ -79,6 +81,18 @@ public class Matrix {
}
}
public void randomAdjazenzMatrix() {
Random r = new Random();
for(int columnIndex=0; columnIndex < columnLength; columnIndex++) {
for(int rowIndex=0; rowIndex < rowLength; rowIndex++) {
if(rowIndex == columnIndex) {
continue;
}
matrix[rowIndex][columnIndex] = r.nextInt(2);
}
}
}
public String toString() {
String s = "";
for(int columnIndex=0; columnIndex < columnLength; columnIndex++) {

View File

@ -1,6 +1,6 @@
public class TestMatrix {
public static void main(String[] args) {
String pathToProgramRoot = "";
String pathToProgramRoot = "/home/rene/projects/Java/graphprogram";
Matrix matrix = new Matrix(pathToProgramRoot + "/csv/graph.csv");
Matrix scalarProduct;
@ -12,5 +12,8 @@ public class TestMatrix {
scalarProduct = matrix.multiply(matrix);
System.out.println("\nScalarProduct A²: \n" + scalarProduct);
Matrix bruh = new Matrix(100, 100);
System.out.println(bruh);
}
}