Compare commits

..

3 Commits

Author SHA1 Message Date
Rhinemann 100398953a Slight rehash. 2023-05-08 10:53:20 +03:00
Rhinemann 0d5e3d5ffe Slight rehash. 2023-05-08 10:51:54 +03:00
Rhinemann fd8c37c7cb Slight rehash. 2023-05-08 10:48:22 +03:00
4 changed files with 16 additions and 15 deletions

View File

@ -1,3 +1,5 @@
package OOP.Java.lab_1;
import java.util.Scanner; import java.util.Scanner;
public class lab_1 { public class lab_1 {

View File

@ -1,3 +1,5 @@
package OOP.Java.lab_1
fun protectedInput(variableName: String): Int { fun protectedInput(variableName: String): Int {
do { do {
try { try {

View File

@ -1,3 +1,5 @@
package OOP.Java.lab_2;
import java.util.Scanner; import java.util.Scanner;
public class lab_2 { public class lab_2 {
@ -23,9 +25,8 @@ public class lab_2 {
public static String format(int number) { public static String format(int number) {
int width = String.valueOf(number).length() + 1; int width = String.valueOf(number).length() + 1;
String format = "|%" + width + "d ";
return format; return "|%" + width + "d ";
} }
public static double average(short[] row) { public static double average(short[] row) {
@ -35,18 +36,15 @@ public class lab_2 {
sum += element; sum += element;
} }
double result = sum / row.length; return (double) sum / row.length;
return result;
} }
public static void main(String[] args) { public static void main(String[] args) {
short a, rows = 0, columns = 0; short rows, columns;
String format;
Scanner input = new Scanner(System.in); 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); "A constant must be a short-data type integer, try again.", input);
System.out.println(); System.out.println();
@ -69,7 +67,7 @@ public class lab_2 {
System.out.println(); System.out.println();
System.out.println("Matrix B:"); System.out.println("Matrix B:");
format = format(rows * columns); String format = format(rows * columns);
for (short i = 0; i < rows; i++) { for (short i = 0; i < rows; i++) {
for (short j = 0; j < columns; j++) { 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 i = 0; i < matrix_B.length; i++) {
for (short j = 0; j < matrix_B[i].length; j++) { 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]); System.out.printf(format, matrix_B[i][j]);
} }

View File

@ -19,7 +19,6 @@ public class lab_3 {
result = string.substring(leftBoundary + 1, rightBoundary); result = string.substring(leftBoundary + 1, rightBoundary);
maxStrLength = rightBoundary - leftBoundary - 1; maxStrLength = rightBoundary - leftBoundary - 1;
} }
return;
} }
public static int longestPalSubstr(StringBuilder string) public static int longestPalSubstr(StringBuilder string)
@ -40,9 +39,9 @@ public class lab_3 {
public static String compareStrings(StringBuilder builder) { public static String compareStrings(StringBuilder builder) {
for (int leftBoundary = 0; leftBoundary <= builder.length(); leftBoundary++) { for (int leftBoundary = 0; leftBoundary <= builder.length(); leftBoundary++) {
for (int rightBoundary = builder.length(); leftBoundary >= 0; rightBoundary--) { for (int rightBoundary = builder.length(); rightBoundary >= leftBoundary; rightBoundary--) {
if (result.equals(builder.substring(leftBoundary, rightBoundary).toString().toLowerCase().replaceAll("[^a-z]",""))) { if (result.equals(builder.substring(leftBoundary, rightBoundary).toLowerCase().replaceAll("[^a-z]",""))) {
return builder.substring(leftBoundary, rightBoundary).toString(); return builder.substring(leftBoundary, rightBoundary);
} }
} }
} }
@ -52,7 +51,7 @@ public class lab_3 {
public static void main(String[] args) { public static void main(String[] args) {
StringBuilder stringToDetect = new StringBuilder("Eva, can I see bees in a cave?"); StringBuilder stringToDetect = new StringBuilder("Eva, can I see bees in a cave?");
System.out.println("Initial string: " + stringToDetect.toString()); System.out.println("Initial string: " + stringToDetect);
System.out.println("Length is: " + longestPalSubstr(stringToDetect)); System.out.println("Length is: " + longestPalSubstr(stringToDetect));
} }
} }