Snippets Collections
import java.util.*;
import java.io.*;
  
class GFG { 
    
    static boolean areRotations(String s1,String s2)
    {
        if(s1.length()!=s2.length())
            return false;
            
        return ((s1+s1).indexOf(s2)>=0);
    }

    public static void main(String args[]) 
    {   
        String s1 = "ABCD";String s2="CDAB";
        
        if(areRotations(s1,s2)){
            System.out.println("Strings are rotations of each other");
        }
        else{
            System.out.println("Strings are not rotations of each other");
        }  
    } 
} 
star

Tue Feb 08 2022 12:11:58 GMT+0000 (Coordinated Universal Time)

#java #gfg #geeksforgeeks #lecture #string #rotations

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension