Avatar of gudii9
gudii9
Flag for United States of America

asked on 

strDist challenge

Hi,

I am working on below challenge.
http://codingbat.com/prob/p195413
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));
	    	  
	    	}
}

Open in new window

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
JavaJava EEProgramming

Avatar of undefined
Last Comment
sarabande

8/22/2022 - Mon