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
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE