fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. Ideone p = new Ideone();
  13. System.out.println(p.strCopies("iiijjj", "i", 3));
  14. System.out.println(p.strCopies("iiijjj", "i", 3));
  15. }
  16.  
  17. int count;
  18. public boolean strCopies(String str, String sub, int n) {
  19. if (str.indexOf(sub) != -1) {
  20. count++;
  21. strCopies(str.substring(str.indexOf(sub)+1), sub, n);
  22. }
  23. if (count == n) {
  24. return true;
  25. }
  26. else {
  27. count = 0;
  28. return false;
  29. }
  30. }
  31. }
Success #stdin #stdout 0.07s 3359744KB
stdin
Standard input is empty
stdout
true
false