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 String foo(String s, String find)
  11. {
  12. String arr[] = s.split("\\.");
  13. for (int i = 1; i < arr.length - 1; i++)
  14. {
  15. if (arr[i].indexOf(find) != -1)
  16. return arr[i - 1] + "." + arr[i] + "." + arr[i + 1];
  17. }
  18. return "";
  19. }
  20. public static void main (String[] args) throws java.lang.Exception
  21. {
  22. String str = "Abc.Def.Ghk.Gml.Zkb.";
  23. String input = "e";
  24. String result = foo(str, input);
  25. System.out.println(result);
  26. }
  27. }
Success #stdin #stdout 0.11s 320576KB
stdin
Standard input is empty
stdout
Abc.Def.Ghk