Skip to content

Instantly share code, notes, and snippets.

@gansai
Last active August 24, 2019 00:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gansai/1587a73ed650459b6f0416ab0994ce34 to your computer and use it in GitHub Desktop.
Save gansai/1587a73ed650459b6f0416ab0994ce34 to your computer and use it in GitHub Desktop.
check for string rotation in java
public class IsRotation {
public static void main(String[] args) {
String a = "ABCD";
String b = "DABC";
System.out.println(isRotation(a,b));
String c = "DCAB";
System.out.println(isRotation(a,c));
}
private static boolean isRotation(String a, String b) {
if(a.length() == b.length() && (( a + a).indexOf(b) ) != -1){
return true;
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment