troubleshooting Question

removing x challenge

Avatar of gudii9
gudii9Flag for United States of America asked on
JavaJava EEProgramming Languages-Other
25 Comments2 Solutions229 ViewsLast Modified:
Hi,

I am trying below example
http://codingbat.com/prob/p171260

I wrote my code as below
public String stringX(String str) {
StringBuilder sb=new StringBuilder("str");
for(int i=0;i<str.length()-1;i++)
{
if(str.substring(i,i+1).equals("x"))
sb.delete(i,i+1);
return sb.toString();
}
return sb.toString();
}

Please advise on how to fix and improve the my code. Thanks in advance
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 25 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 25 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