/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
public class Main {
public static void main(String[] args) {
String s= "TOKYO";
String t = "KYOTO";
if (sonAmigas( s, t )) {
System.out.printf( "Las cadenas '%s' y '%s' son amigas", s, t );
} else {
System.out.printf( "Las cadenas '%s' y '%s' NO son amigas", s, t );
}
}
public static boolean sonAmigas(String S, String T) {
if (S.length() != T.length()) {
return false;
}
for (int i = 1; i < S.length(); i++) {
String u = S.substring( 0, i );
String v = S.substring( i );
if (T.equals( v + u )) {
return true;
}
}
return false;
}
}