Saturday, June 13, 2015

Q.8 - Write a program to determine whether a string is cyclic shift (rotation) of other.

public class Rotation{
public static void main(String args[]){

System.out.println(Rotation.isRotation("ashish","hishas"));
}

static boolean isRotation(String actual, String checkString){

if(actual.length() != checkString.length())
return false;

if((checkString+checkString).indexOf(actual)!=-1)
return true;
else
return false;
}
}

No comments:

Post a Comment