troubleshooting Question

xyzThere java challenge

Avatar of gudii9
gudii9Flag for United States of America asked on
Java EEJavaProgrammingProgramming Languages-OtherPuzzles / Riddles
153 Comments2 Solutions1310 ViewsLast Modified:
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;
I am getting below result
Expected      Run            
xyzThere("abcxyz") → true      true      OK         
xyzThere("") → false      true      X         
xyzThere("") → 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("") → false      true      X         
xyzThere("12xyz") → true      true      OK         
xyzThere("") → 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
Join our community to see this answer!
Unlock 2 Answers and 153 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 153 Comments.
Try for 7 days

”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.

-Mike Kapnisakis, Warner Bros