Compare commits
No commits in common. "100398953a54bfabb3c83719d22a434702804683" and "a8cbadbe7d0c0fef9fec7c981af1aa5e53ff9925" have entirely different histories.
100398953a
...
a8cbadbe7d
|
@ -1,5 +1,3 @@
|
|||
package OOP.Java.lab_1;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class lab_1 {
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
package OOP.Java.lab_1
|
||||
|
||||
fun protectedInput(variableName: String): Int {
|
||||
do {
|
||||
try {
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
package OOP.Java.lab_2;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class lab_2 {
|
||||
|
@ -25,8 +23,9 @@ public class lab_2 {
|
|||
|
||||
public static String format(int number) {
|
||||
int width = String.valueOf(number).length() + 1;
|
||||
String format = "|%" + width + "d ";
|
||||
|
||||
return "|%" + width + "d ";
|
||||
return format;
|
||||
}
|
||||
|
||||
public static double average(short[] row) {
|
||||
|
@ -36,15 +35,18 @@ public class lab_2 {
|
|||
sum += element;
|
||||
}
|
||||
|
||||
return (double) sum / row.length;
|
||||
double result = sum / row.length;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
short rows, columns;
|
||||
short a, rows = 0, columns = 0;
|
||||
String format;
|
||||
|
||||
Scanner input = new Scanner(System.in);
|
||||
|
||||
final short a = protectedInput("Input a constant to multiply a matrix by: ",
|
||||
a = protectedInput("Input a constant to multipy a matrix by: ",
|
||||
"A constant must be a short-data type integer, try again.", input);
|
||||
|
||||
System.out.println();
|
||||
|
@ -67,7 +69,7 @@ public class lab_2 {
|
|||
System.out.println();
|
||||
System.out.println("Matrix B:");
|
||||
|
||||
String format = format(rows * columns);
|
||||
format = format(rows * columns);
|
||||
|
||||
for (short i = 0; i < rows; i++) {
|
||||
for (short j = 0; j < columns; j++) {
|
||||
|
@ -86,7 +88,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] *= (a);
|
||||
matrix_B[i][j] *= (short) (a);
|
||||
|
||||
System.out.printf(format, matrix_B[i][j]);
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ public class lab_3 {
|
|||
result = string.substring(leftBoundary + 1, rightBoundary);
|
||||
maxStrLength = rightBoundary - leftBoundary - 1;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
public static int longestPalSubstr(StringBuilder string)
|
||||
|
@ -39,9 +40,9 @@ public class lab_3 {
|
|||
|
||||
public static String compareStrings(StringBuilder builder) {
|
||||
for (int leftBoundary = 0; leftBoundary <= builder.length(); leftBoundary++) {
|
||||
for (int rightBoundary = builder.length(); rightBoundary >= leftBoundary; rightBoundary--) {
|
||||
if (result.equals(builder.substring(leftBoundary, rightBoundary).toLowerCase().replaceAll("[^a-z]",""))) {
|
||||
return builder.substring(leftBoundary, rightBoundary);
|
||||
for (int rightBoundary = builder.length(); leftBoundary >= 0; rightBoundary--) {
|
||||
if (result.equals(builder.substring(leftBoundary, rightBoundary).toString().toLowerCase().replaceAll("[^a-z]",""))) {
|
||||
return builder.substring(leftBoundary, rightBoundary).toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -51,7 +52,7 @@ public class lab_3 {
|
|||
public static void main(String[] args) {
|
||||
StringBuilder stringToDetect = new StringBuilder("Eva, can I see bees in a cave?");
|
||||
|
||||
System.out.println("Initial string: " + stringToDetect);
|
||||
System.out.println("Initial string: " + stringToDetect.toString());
|
||||
System.out.println("Length is: " + longestPalSubstr(stringToDetect));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue