forked from sumeet-automation/selenium-java-interview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion56.java
More file actions
21 lines (18 loc) · 805 Bytes
/
Copy pathQuestion56.java
File metadata and controls
21 lines (18 loc) · 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package string;
public class Question56 {
public static void main(String[] args) {
final String word = "AAAAAxyzBBCCDEF";
final String wordToInspect = "xyz";
System.out.println(isWordInMiddle(word, wordToInspect));
}
private static boolean isWordInMiddle(String word, String wordToInspect) {
final int indexOfInspectingWord = word.indexOf(wordToInspect);
if (-1 == indexOfInspectingWord) {
return false;
} else {
final int traillingWordLength = word.substring(0, indexOfInspectingWord).length();
final int leadingWordLength = word.substring(indexOfInspectingWord + wordToInspect.length()).length();
return Math.abs(leadingWordLength - traillingWordLength) > 1 ? false : true;
}
}
}