public boolean xyzThere(String str) {
int xPos= str.indexOf('x');
int len=str.length();
String sub=str.substring(xPos,len);
if(sub.equals("xyz")){
return true;
}
else{
return false;
}
}
I am getting below resultExpected Run
xyzThere("abcxyz") → true true OK
xyzThere("abc.xyz") → false true X
xyzThere("xyz.abc") → true false X
xyzThere("abcxy") → false false OK
xyzThere("xyz") → true true OK
xyzThere("xy") → false false OK
xyzThere("x") → false false OK
xyzThere("") → false Exception:java.lang.StringIndexOutOf BoundsExce ption: String index out of range: -1 (line number:5) X
xyzThere("abc.xyzxyz") → true false X
xyzThere("abc.xxyz") → true false X
xyzThere(".xyz") → false true X
xyzThere("12.xyz") → false true X
xyzThere("12xyz") → true true OK
xyzThere("1.xyz.xyz2.xyz")→ false false OK
other tests
X
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Most Valuable Expert award recognizes technology experts who passionately share their knowledge with the community, demonstrate the core values of this platform, and go the extra mile in all aspects of their contributions. This award is based off of nominations by EE users and experts. Multiple MVEs may be awarded each year.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.