GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — java-basics/java-programs/StringRotation.java at master · learning-zone/java-basics Expand file tree/ Copy pathStringRotation.javaMore file actions 35 lines (31 loc) · 933 Bytes / Copy pathStringRotation.javaFile metadata and controls35 lines (31 loc) · 933 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 package misc; /** * Algorithm:- * 1. Create a temp string and store concatenation of str1 to str1 in temp. * temp = str1.str1 * 2. If str2 is a substring of temp then str1 and str2 are * rotations of each other. * * Example: * str1 = "ABACD" * str2 = "CDABA" * * temp = str1.str1 = "ABACDABACD" * Since str2 is a substring of temp, str1 and str2 are * rotations of each other. * */ public class StringRotation { static boolean isRotation(String str1, String str2) { return (str1.length() == str2.length()) && ((str1 + str2).indexOf(str2) != -1); } public static void main(String[] args) { String str1 = "AACD"; String str2 = "ACDA"; if(isRotation(str1, str2)) { System.out.println("Strings are rotations of each other"); } else { System.out.println("Strings are not rotations of each other"); } } } |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |