From 3f15c4c7248ec18cea8a8c3f4a860904f9d70700 Mon Sep 17 00:00:00 2001 From: dymik739 Date: Sat, 18 Mar 2023 11:18:59 +0200 Subject: [PATCH] finished doing lab2 in wrong variable type --- labs/2/Main.java | 23 ++++++++++++++++++----- labs/2/web/double-matrix.py | 2 ++ labs/2/{ => web}/matrix.py | 0 3 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 labs/2/web/double-matrix.py rename labs/2/{ => web}/matrix.py (100%) diff --git a/labs/2/Main.java b/labs/2/Main.java index cd65a56..c9de689 100644 --- a/labs/2/Main.java +++ b/labs/2/Main.java @@ -64,16 +64,29 @@ public class Main { System.exit(1); } } - - int[][] matrix = loadMatrixFromFile(matrix_file); + // loading matrix data from file + int[][] raw_m = loadMatrixFromFile(matrix_file); + + // creating original matrix object + System.out.println("Original matrix:"); + Matrix m = new Matrix(); + m.init(raw_m); + + // transposing + m.transpose(); + System.out.println("\nTransposed matrix:"); + m.print(); + + // avg + System.out.println("\nAverage value is " + m.getAvg()); } private static void fetchResource(String remote_url, String output_filename) { try { BufferedInputStream in = new BufferedInputStream(new URL(remote_url).openStream()); FileOutputStream fileOutputStream = new FileOutputStream(output_filename); - + byte dataBuffer[] = new byte[1024]; int bytesRead; while ((bytesRead = in.read(dataBuffer, 0, 1024)) != -1) { @@ -138,11 +151,11 @@ public class Main { } for (int j = 0; j < baked_matrix_lines.get(i).length; j++) { - System.out.print(baked_matrix_lines.get(i)[j] + " "); + //System.out.print(baked_matrix_lines.get(i)[j] + " "); baked_matrix[i][j] = Integer.parseInt(baked_matrix_lines.get(i)[j]); } - System.out.print("\n"); + //System.out.print("\n"); } return baked_matrix; diff --git a/labs/2/web/double-matrix.py b/labs/2/web/double-matrix.py new file mode 100644 index 0000000..9ebb96a --- /dev/null +++ b/labs/2/web/double-matrix.py @@ -0,0 +1,2 @@ +import random +print("Content-Type: text/plain\n\n" + "\n".join([" ".join(list(map(str, [round((random.random()-0.5)*200, 4) for i in range(7)]))) for i in range(7)])) diff --git a/labs/2/matrix.py b/labs/2/web/matrix.py similarity index 100% rename from labs/2/matrix.py rename to labs/2/web/matrix.py