i am trying to write a cose that gets two strings s1 ,s2.
return true if s2 is a substring of s1
this is the method :
public static boolean isSubstring (String s1, String s2)
{
//2 stop condition
if(s1.length() == 0)
return false;
if(s2.length() == 0)
return true;
//in case the first characters in both strings are equal
if(s1.charAt(0) == s2.charAt(0))
if(isPrefix(s1.substring(1), s2.substring(1)))
return true;
return isSubstring(s1.substring(1),s2);
}
//this is the method that inside the method
public static boolean isSubstring (String s1, String s2)
{
//2 stop condition
if(s1.length() == 0)
return false;
if(s2.length() == 0)
return true;
//in case the first characters in both strings are equal
if(s1.charAt(0) == s2.charAt(0))
if(isPrefix(s1.substring(1), s2.substring(1)))
return true;
return isSubstring(s1.substring(1),s2);
}
this is the main :
public class Substring{
public static void main(String[] args){
isSubstring(abcde,abc);
}
}
getting alot of error from this sort :
Compilation Errors Detected
File: USER_155552/source/isPrefix.java
Line: 2
class, interface, or enum expected
please help!!
2 string using recursion
-
- Posts: 63
- Joined: Sun Jan 07, 2018 6:30 pm
Re: 2 string using recursion
Hi!
The problem is that you had methods not surrounded by classes inside the files. I accessed your program and changed it so now each method is in its own class. Tell me if that fixes the problem
Regards!
David
The problem is that you had methods not surrounded by classes inside the files. I accessed your program and changed it so now each method is in its own class. Tell me if that fixes the problem
Regards!
David
-
- Posts: 32
- Joined: Thu Dec 21, 2017 10:06 pm
Re: 2 string using recursion
yes it worked !
thanks alot David
thanks alot David
