18. Program to determine whether one string is a rotation of another
class Main{
static boolean isRotation(String s1, String s2){
int count = 0;
if(s1.length() != s2.length()){
return false;
}
String temp = s1+s1;
for(int i = 0; i < (temp.length() - s2.length() + 1); i++){
count = 0;
while(count < s2.length() && temp.charAt(i) == s2.charAt(count)){
count++;
i++;
}
if(count == s2.length()){
return true;
}
}
return false;
}
public static void main(String[] args){
System.out.println((isRotation("ABCD", "DABC")) ? "String is rotated" : "String is not rotated");
}
}
OUTPUT
String is rotated