diff --git a/Java/lab_3/lab_3.java b/Java/lab_3/lab_3.java index 6c6d1e4..32c1e40 100644 --- a/Java/lab_3/lab_3.java +++ b/Java/lab_3/lab_3.java @@ -15,7 +15,7 @@ public class lab_3 { return pTextLower; } */ - static void cSubUtil(String string, int leftBoundary, int rightBoundary) + public static void cSubUtil(String string, int leftBoundary, int rightBoundary) { // check if the indices lie in the range of string // and also if it is palindrome @@ -33,7 +33,7 @@ public class lab_3 { return; } - static int longestPalSubstr(String string) + public static int longestPalSubstr(String string) { result = ""; maxStrLength = 1; @@ -49,11 +49,26 @@ public class lab_3 { return maxStrLength; } + public static String compareStrings(StringBuilder builder) { + System.out.println(result); + for (int leftBoundary = 0; leftBoundary < builder.length(); leftBoundary++) { + for (int rightBoundary = builder.length(); rightBoundary > 0; rightBoundary--) { + if (result.equals(builder.substring(rightBoundary, rightBoundary).toString().toLowerCase().replaceAll("[^a-z]",""))) { + return builder.substring(rightBoundary, rightBoundary).toString(); + } + } + } + return ""; + } + public static void main(String[] args) { StringBuilder stringToDetect = new StringBuilder("Eva, can I see bees in a cave?"); - String stripped = stringToDetect.toString().replaceAll("[\\.,:-\\?]? ?", ""); + String stripped = stringToDetect.toString().toLowerCase().replaceAll("[^a-z]",""); System.out.println("Initial string: " + stringToDetect.toString()); System.out.println("Length is: " + longestPalSubstr(stripped)); + System.out.println(compareStrings(stringToDetect)); + + // System.out.println("Eva, can I see bees in a cave?".length()); } } diff --git a/Rust/lab_1/src/main.rs b/Rust/lab_1/src/main.rs index 295ec18..9cd8242 100644 --- a/Rust/lab_1/src/main.rs +++ b/Rust/lab_1/src/main.rs @@ -19,4 +19,4 @@ fn main() { let s: f32 = ((b + m) as f32 / 2f32) * ((m - b + 1) * (n - a + 1)) as f32; println!("S = {}", s); -} +} \ No newline at end of file