commit 76f2823228c3e55ac3644c14400f40cdd154002e Author: Leonora Tindall Date: Sun Oct 6 21:38:37 2019 -0500 Working single threaded. diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..217af47 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,23 @@ + + + + + + diff --git a/.idea/description.html b/.idea/description.html new file mode 100644 index 0000000..db5f129 --- /dev/null +++ b/.idea/description.html @@ -0,0 +1 @@ +Simple Java application that includes a class with main() method \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..c08f7b9 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..6dbbdd6 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..def6a6a --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..bf326b1 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1570414923071 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CSCI335Barriers.iml b/CSCI335Barriers.iml new file mode 100644 index 0000000..d5c0743 --- /dev/null +++ b/CSCI335Barriers.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/out/production/CSCI335Barriers/Main.class b/out/production/CSCI335Barriers/Main.class new file mode 100644 index 0000000..1c46647 Binary files /dev/null and b/out/production/CSCI335Barriers/Main.class differ diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..f787320 --- /dev/null +++ b/src/Main.java @@ -0,0 +1,67 @@ +import java.util.Random; + +public class Main { + static int SIZE = 4; + int [][] a; + int [][] b; + int [][] c; + int [][] d; + + public static void main(String[] args) { + var main = new Main(); + main.execute(); + } + + void execute() { + var random = new Random(); + a = new int[SIZE][SIZE]; + b = new int[SIZE][SIZE]; + c = new int[SIZE][SIZE]; + d = new int[SIZE][SIZE]; + for (int row = 0; row < SIZE; row++) { + for (int col = 0; col < SIZE; col++) { + a[row][col] = random.nextInt(10); + } + } + for (int row = 0; row < SIZE; row++) { + for (int col = 0; col < SIZE; col++) { + b[row][col] = random.nextInt(10); + } + } + + printMatrix(a, "A"); + printMatrix(b, "B"); + + for (int row = 0; row < SIZE; row++) { + for (int col = 0; col < SIZE; col++) { + c[row][col] = computeAtPosition(a, b, row, col); + } + } + printMatrix(c, "C"); + + for (int row = 0; row < SIZE; row++) { + for (int col = 0; col < SIZE; col++) { + d[row][col] = computeAtPosition(c, a, row, col); + } + } + printMatrix(d, "D"); + } + + static int computeAtPosition(int[][] m1, int[][] m2, int row, int col) { + int product = 0; + for (int k = 0; k < SIZE; k++) { + product += m1[row][k] * m2[k][col]; + } + return product; + } + + static void printMatrix(int[][] m1, String label) { + System.out.println(label); + for (int i = 0; i < SIZE; i++) { + for (int j = 0; j < SIZE; j++) { + System.out.print("" + m1[i][j] + "\t"); + } + System.out.println(); + } + } +}