troubleshooting Question

strDist challenge

Avatar of gudii9
gudii9Flag for United States of America asked on
JavaJava EEProgramming
35 Comments2 Solutions394 ViewsLast Modified:

I am working on below challenge.
Psedo code:
1. find length of str starting and ending with sub.
2. return the length

I wrote my code as below and not passing all tests
public int strDist(String str, String sub) {
   if (str.length() <2){ 
	    	return 0;
	    if (str.startsWith( sub) {
	    	return 1 + strDist(str.substring(2));
	    	else {
		   return strDist(str.substring(1));
i am getting below error

Compile problems:

Error:      return 1 + strDist(str.substring(2));
The method strDist(String, String) in the type Shell is not applicable for the arguments (String)

see Example Code to help with compile problems
Any improvements or alternate approaches?      

please advise
Join our community to see this answer!
Unlock 2 Answers and 35 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 35 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