2 string using recursion
Posted: Fri Feb 09, 2018 12:49 am
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!!
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!!