fork(1) 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. static int indexOf(String str, String sub) {
  11. if (str.length() < sub.length()) return -1;
  12. if (str.startsWith(sub)) return 0;
  13. int res = indexOf(str.substring(1), sub);
  14. return res < 0 ? res : 1+res;
  15. }
  16. public static void main (String[] args) throws java.lang.Exception
  17. {
  18. System.out.println(indexOf("Barak Obama", "Obama"));
  19. System.out.println(indexOf("Barak Obama", "Osama"));
  20. }
  21. }
Success #stdin #stdout 0.09s 320576KB
stdin
Standard input is empty
stdout
6
-1