Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static boolean composedBySubString(String s) {
- if (s == null || s.length() < 2) {
- return false;
- }
- int step = 1;
- while (step <= (s.length() / 2)) {
- if (s.length() % step == 0) {
- String subString = s.substring(0, step);
- int start = step;
- boolean found = true;
- while (start + step < s.length()) {
- if (!s.substring(start, step).equals(subString)) {
- found = false;
- break;
- }
- start += step;
- }
- if (found) {
- return true;
- }
- }
- step += 1;
- }
- return false;
- }
Add Comment
Please, Sign In to add comment