troubleshooting Question

string challenge middle characters

Avatar of gudii9
gudii9Flag for United States of America asked on
Programming Languages-OtherJavaJava EE
5 Comments2 Solutions314 ViewsLast Modified:

I am working on below coding challenge
i wrote as below
public String middleTwo(String str) {
  int len=str.length();
  return str.substring((len/2)-1,(len/2)+1);
  return "";

My test cases are passing
i would like to know how can improve on my above code. For string odd length  i returned "". Not sure if that is what challenge is expecting me to do.Please advise.Thanks in advance
Join our community to see this answer!
Unlock 2 Answers and 5 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 5 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