From 5c45e06dd16a830338a322b23120a77643220e3c Mon Sep 17 00:00:00 2001 From: Tsvetoslav Tsvetkov Date: Sun, 19 Jun 2022 20:53:19 +0300 Subject: [PATCH] Process all data in array Ch01,Q1_05_One_Away --- .../Q1_05_One_Away/QuestionA.java | 11 +++++++---- .../Q1_05_One_Away/QuestionB.java | 18 ++++++++---------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Java/Ch 01. Arrays and Strings/Q1_05_One_Away/QuestionA.java b/Java/Ch 01. Arrays and Strings/Q1_05_One_Away/QuestionA.java index 3c59b6a17..1a07adc8f 100644 --- a/Java/Ch 01. Arrays and Strings/Q1_05_One_Away/QuestionA.java +++ b/Java/Ch 01. Arrays and Strings/Q1_05_One_Away/QuestionA.java @@ -46,10 +46,13 @@ public static boolean oneEditAway(String first, String second) { } public static void main(String[] args) { - String a = "pse"; - String b = "pale"; - boolean isOneEdit = oneEditAway(a, b); - System.out.println(a + ", " + b + ": " + isOneEdit); + String[][] pairs = {{"pale", "ple"}, {"pales", "pale"}, {"pale", "bale"},{"pale","bae"}}; + for (String[] pair: pairs) { + String a = pair[0]; + String b = pair[1]; + boolean isOneEdit = oneEditAway(a, b); + System.out.println(a + ", " + b + ": " + isOneEdit); + } } } diff --git a/Java/Ch 01. Arrays and Strings/Q1_05_One_Away/QuestionB.java b/Java/Ch 01. Arrays and Strings/Q1_05_One_Away/QuestionB.java index 5b2b5f723..f239fe8f3 100644 --- a/Java/Ch 01. Arrays and Strings/Q1_05_One_Away/QuestionB.java +++ b/Java/Ch 01. Arrays and Strings/Q1_05_One_Away/QuestionB.java @@ -1,7 +1,7 @@ package Q1_05_One_Away; public class QuestionB { -public static boolean oneEditAway(String first, String second) { + public static boolean oneEditAway(String first, String second) { /* Length checks. */ if (Math.abs(first.length() - second.length()) > 1) { return false; @@ -33,15 +33,13 @@ public static boolean oneEditAway(String first, String second) { public static void main(String[] args) { - String a = "palee"; - String b = "pale"; - boolean isOneEdit1 = oneEditAway(a, b); - System.out.println(a + ", " + b + ": " + isOneEdit1); - - String c = "pale"; - String d = "pkle"; - boolean isOneEdit2 = oneEditAway(c, d); - System.out.println(c + ", " + d + ": " + isOneEdit2); + String[][] pairs = {{"pale", "ple"}, {"pales", "pale"}, {"pale", "bale"},{"pale","bae"}}; + for (String[] pair: pairs) { + String a = pair[0]; + String b = pair[1]; + boolean isOneEdit = oneEditAway(a, b); + System.out.println(a + ", " + b + ": " + isOneEdit); + } } }