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. String str="AAAABBBBAAAAAA";
  13. String pattern="BAA";
  14. search(str,pattern);
  15. }
  16.  
  17. public static void search(String str,String pattern){
  18. int i=0,j=0;
  19. for( i=0;i<str.length();i++){
  20. for( j=0;j<pattern.length();j++){
  21.  
  22.  
  23. if(str.charAt(i+j)!=pattern.charAt(j))
  24. break;
  25. }
  26. if(j==pattern.length())
  27. System.out.println("Pattern Match Found");
  28. }
  29.  
  30. }
  31.  
  32.  
  33. }
Success #stdin #stdout 0.05s 4386816KB
stdin
Standard input is empty
stdout
Pattern Match Found