Sunday, October 28, 2018

Can you write an algorithm to check if a string is rotation of each other or not ?

Problem statement:
write an algorithm to check if a string is a rotation of each other or not!!
  1. public class CheckStringRotation {
  2.     public static void main(String args[]) {
  3.         String str1 = "ishaan";
  4.         String str2 = "aanish";
  5.         String temp = str1.concat(str1);
  6.         if (temp.contains(str2)) {
  7.             System.out.println(str2 + " is a rotation of " + str1);
  8.         } else {
  9.             System.out.println(str2 + " is not a rotation of " + str1);
  10.         }
  11.     }
  12. }
Output:
aanish is the rotation of ishaan

No comments:

Post a Comment

How to run standalone mock server on local laptop

 Please download the standalone wiremock server from Direct download section at the bottom of the page.  Download and installation Feel fre...