From fd8c37c7cb8c2d9beb6250a2b171fdb580cdfe9f Mon Sep 17 00:00:00 2001 From: Rhinemann Date: Mon, 8 May 2023 10:44:41 +0300 Subject: [PATCH] Slight rehash. --- Java/lab_1/lab_1.java | 2 ++ Java/lab_1/lab_1.kt | 2 ++ Java/lab_2/lab_2.java | 18 ++++++++---------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Java/lab_1/lab_1.java b/Java/lab_1/lab_1.java index e3953c5..c530901 100644 --- a/Java/lab_1/lab_1.java +++ b/Java/lab_1/lab_1.java @@ -1,3 +1,5 @@ +package OOP.Java.lab_1; + import java.util.Scanner; public class lab_1 { diff --git a/Java/lab_1/lab_1.kt b/Java/lab_1/lab_1.kt index 48a2ef6..b16b4f7 100644 --- a/Java/lab_1/lab_1.kt +++ b/Java/lab_1/lab_1.kt @@ -1,3 +1,5 @@ +package OOP.Java.lab_1 + fun protectedInput(variableName: String): Int { do { try { diff --git a/Java/lab_2/lab_2.java b/Java/lab_2/lab_2.java index e371887..4a97358 100644 --- a/Java/lab_2/lab_2.java +++ b/Java/lab_2/lab_2.java @@ -1,3 +1,5 @@ +package OOP.Java.lab_2; + import java.util.Scanner; public class lab_2 { @@ -23,9 +25,8 @@ public class lab_2 { public static String format(int number) { int width = String.valueOf(number).length() + 1; - String format = "|%" + width + "d "; - return format; + return "|%" + width + "d "; } public static double average(short[] row) { @@ -35,18 +36,15 @@ public class lab_2 { sum += element; } - double result = sum / row.length; - - return result; + return (double) sum / row.length; } public static void main(String[] args) { - short a, rows = 0, columns = 0; - String format; + short rows, columns; Scanner input = new Scanner(System.in); - a = protectedInput("Input a constant to multipy a matrix by: ", + final short a = protectedInput("Input a constant to multiply a matrix by: ", "A constant must be a short-data type integer, try again.", input); System.out.println(); @@ -69,7 +67,7 @@ public class lab_2 { System.out.println(); System.out.println("Matrix B:"); - format = format(rows * columns); + String format = format(rows * columns); for (short i = 0; i < rows; i++) { for (short j = 0; j < columns; j++) { @@ -88,7 +86,7 @@ public class lab_2 { for (short i = 0; i < matrix_B.length; i++) { for (short j = 0; j < matrix_B[i].length; j++) { - matrix_B[i][j] *= (short) (a); + matrix_B[i][j] *= (a); System.out.printf(format, matrix_B[i][j]); }