Created
June 26, 2014 22:47
-
-
Save jyhjuzi/1b818b85eeff95152460 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Q1_8{ | |
public static void main(String args[]){ | |
String test1 = "test"; | |
String test2 = "estt"; | |
System.out.println(isRotation(test1, test2)); | |
} | |
private static boolean isRotation(String s1, String s2){ | |
if(s1.length() != s2.length()) | |
return false; | |
String s= s2+s2; | |
if(isSubstring(s1,s)) | |
return true; | |
else return false; | |
} | |
private static boolean isSubstring(String s1, String s2){ | |
if(s1.length()> s2.length()) | |
return false; | |
for(int i = 0; i<=s2.length()-s1.length(); i++){ | |
if(s2.substring(i,i+s1.length()).equals(s1)) | |
return true; | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment