Question: Write an efficient program to test if two given String is a rotation of each other or not, Ex: If the given String is XYZ

Write an efficient program to test if two given String is a rotation of each other or not, Ex:

If the given String is "XYZ" and "ZXY" then your function should return true. But if the input is "XYZ" and "YXZ" then return false.

Example:

Input:

Please enter original string: XYZ Please enter rotation string: ZXY

Output:

XYZ and ZXY are rotation to each other.

Example:

Input:

Please enter original string: XYZ Please enter rotation string: ABC

Output:

Sorry, they are not rotation of another.
Example: Input:

Please enter original string: XYZ Please enter rotation string: ZYX

Output:

Sorry, they are not rotation of another.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The detailed answer for the above question is provided below importjava... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Computer Engineering Questions!