troubleshooting Question

java string challenge issue

Avatar of gudii9
gudii9Flag for United States of America asked on
Programming Languages-OtherJavaJava EE
43 Comments4 Solutions357 ViewsLast Modified:
Hi,

I tried below example
http://codingbat.com/prob/p143825

I wrote like below
public String nonStart(String a, String b) {
StringBuilder sb1=null;
String aFirst=null;
String bFirst=null;
  if(a.length()>1&&b.length()>1){
  aFirst=a.substring(1,a.length());
    bFirst=b.substring(1,b.length());
  return aFirst+bFirst;
  
  }
  return null;
}
it is pasing some and failing in some test cases

Expected	Run		
nonStart("Hello", "There") → "ellohere"	"ellohere"	OK	    
nonStart("java", "code") → "avaode"	"avaode"	OK	    
nonStart("shotl", "java") → "hotlava"	"hotlava"	OK	    
nonStart("ab", "xy") → "by"	"by"	OK	    
nonStart("ab", "x") → "b"	"null"	X	    
nonStart("x", "ac") → "c"	"null"	X	    
nonStart("a", "x") → ""	"null"	X	    
nonStart("kit", "kat") → "itat"	"itat"	OK	    
nonStart("mart", "dart") → "artart"	"artart"	OK	    
other tests
X	
please advise on how to fix and improve my code. thanks in advance
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 4 Answers and 43 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 4 Answers and 43 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