Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process all data in array Ch01,Q1_05_One_Away #238

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions Java/Ch 01. Arrays and Strings/Q1_05_One_Away/QuestionA.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

}
18 changes: 8 additions & 10 deletions Java/Ch 01. Arrays and Strings/Q1_05_One_Away/QuestionB.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}
}

}