Guest User

Untitled

a guest
Oct 20th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. public static boolean composedBySubString(String s) {
  2. if (s == null || s.length() < 2) {
  3. return false;
  4. }
  5. int step = 1;
  6. while (step <= (s.length() / 2)) {
  7. if (s.length() % step == 0) {
  8. String subString = s.substring(0, step);
  9. int start = step;
  10. boolean found = true;
  11. while (start + step < s.length()) {
  12. if (!s.substring(start, step).equals(subString)) {
  13. found = false;
  14. break;
  15. }
  16. start += step;
  17. }
  18. if (found) {
  19. return true;
  20. }
  21. }
  22. step += 1;
  23. }
  24. return false;
  25. }
Add Comment
Please, Sign In to add comment