Problem statement:
write an algorithm to check if a string is a rotation of each other or not!!
write an algorithm to check if a string is a rotation of each other or not!!
- public class CheckStringRotation {
- public static void main(String args[]) {
- String str1 = "ishaan";
- String str2 = "aanish";
- String temp = str1.concat(str1);
- if (temp.contains(str2)) {
- System.out.println(str2 + " is a rotation of " + str1);
- } else {
- System.out.println(str2 + " is not a rotation of " + str1);
- }
- }
- }
Output:
aanish is the rotation of ishaan
No comments:
Post a Comment