We help IT Professionals succeed at work.
Get Started

xyzThere java challenge

Last Modified: 2016-04-13
I am working on below challenge
I tried my code as below
public boolean xyzThere(String str) {
 int xPos= str.indexOf('x');
 int len=str.length();
 String sub=str.substring(xPos,len);
 return true;
 return false;

Open in new window

I am getting below result
Expected      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.StringIndexOutOfBoundsException: 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

how to  improve my approach, results and design of this challenge. How do i make a graphical venn or flow chart or some other relevant diagram to design it before writing code to decide best strategy?
 Please advise
Watch Question
Most Valuable Expert 2014
Top Expert 2015
This problem has been solved!
Unlock 2 Answers and 153 Comments.
See Answers
Why Experts Exchange?

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.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE