Skip to content

Instantly share code, notes, and snippets.

@ilyeshammadi
Created October 9, 2015 23:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilyeshammadi/d7db6475bfcde38a89a4 to your computer and use it in GitHub Desktop.
Save ilyeshammadi/d7db6475bfcde38a89a4 to your computer and use it in GitHub Desktop.
et Voila the challenge is complited B|
import java.util.Objects;
public class Main {
public static void main(String[] args) {
System.out.println(countCouple("abc", "axc"));
}
public static int countCouple(String firstWord, String secondWord) {
int count = 0;
for (int i = 0; i < (firstWord.length() - 1); i++) {
String firstCouple = String.valueOf(firstWord.charAt(i)) + String.valueOf(firstWord.charAt(i + 1));
for (int j = 0; j < (secondWord.length() - 1); j++) {
String secondCouple = String.valueOf(secondWord.charAt(j)) + String.valueOf(secondWord.charAt(j + 1));
if (Objects.equals(firstCouple, secondCouple)) {
count++;
}
}
}
return count;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment